arrange of proj structure
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="BattleField"
|
// file="BattleField"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -29,7 +29,7 @@ using StgSharp.Geometries;
|
|||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
|
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ButtonGroup"
|
// file="ButtonGroup"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="CharacterIndexImage"
|
// file="CharacterIndexImage"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ControllingIntem"
|
// file="ControllingIntem"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="DecorationBox.cs"
|
// file="DecorationBox.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MarkingLable"
|
// file="MarkingLable"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -29,7 +29,7 @@ using StgSharp.Controls;
|
|||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.Timing;
|
using StgSharp.Timing;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="TriggerButton"
|
// file="TriggerButton"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -29,7 +29,7 @@ using StgSharp.Controls;
|
|||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Counter"
|
|
||||||
// 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.Numerics;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public class Counter<T> where T: unmanaged, INumber<T>
|
|
||||||
{
|
|
||||||
|
|
||||||
internal dynamic _value;
|
|
||||||
internal readonly T _defaultDecrement;
|
|
||||||
|
|
||||||
internal readonly T _defaultIncrement;
|
|
||||||
internal readonly T _defaultValue;
|
|
||||||
|
|
||||||
public Counter(T defaultValue, T defaultIncrement, T defaultDecrement)
|
|
||||||
{
|
|
||||||
_value = defaultValue;
|
|
||||||
_defaultValue = defaultValue;
|
|
||||||
_defaultIncrement = defaultIncrement;
|
|
||||||
_defaultDecrement = defaultDecrement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T DecrementSpan => _defaultDecrement;
|
|
||||||
|
|
||||||
public T IncrementSpan => _defaultIncrement;
|
|
||||||
|
|
||||||
public T CurrentSpan => _value - _defaultValue;
|
|
||||||
|
|
||||||
public T Value
|
|
||||||
{
|
|
||||||
get => _value;
|
|
||||||
set => _value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(T value)
|
|
||||||
{
|
|
||||||
_value += value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void QuickAdd()
|
|
||||||
{
|
|
||||||
_value += _defaultIncrement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void QuickSub()
|
|
||||||
{
|
|
||||||
_value -= _defaultDecrement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
_value = _defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Sub(T value)
|
|
||||||
{
|
|
||||||
_value -= value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString() ?? string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Counter<T> operator --(Counter<T> counter)
|
|
||||||
{
|
|
||||||
counter?.QuickSub();
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Counter<T> operator ++(Counter<T> counter)
|
|
||||||
{
|
|
||||||
counter?.QuickAdd();
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator T(Counter<T> counter)
|
|
||||||
{
|
|
||||||
return counter switch
|
|
||||||
{
|
|
||||||
null => T.Zero,
|
|
||||||
_ => counter.Value
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="root"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Internal;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public static unsafe partial class World { }//------------------ end of class ---------------------
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Area"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Internal.FileIO;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// An independent storage area, used as the only folder type in root folder. Contains several
|
|
||||||
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
|
|
||||||
/// cref="SSD" />s in certain RAID mode.
|
|
||||||
/// </summary>
|
|
||||||
public partial class Area { }
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="DataHead"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.HighPerformance;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
|
||||||
public struct SSDSegmentHead
|
|
||||||
{
|
|
||||||
|
|
||||||
[FieldOffset(12)] internal byte size;
|
|
||||||
|
|
||||||
[FieldOffset(0)] internal M128 data;
|
|
||||||
[FieldOffset(13)] public byte selfDefine_1;
|
|
||||||
[FieldOffset(14)] public byte selfDefine_2;
|
|
||||||
[FieldOffset(15)] public byte selfDefine_3;
|
|
||||||
|
|
||||||
[FieldOffset(0)] public int globalID;
|
|
||||||
[FieldOffset(4)] public int nextID;
|
|
||||||
[FieldOffset(8)] public int previousHash;
|
|
||||||
|
|
||||||
public int Size
|
|
||||||
{
|
|
||||||
get => ((int)size) + 1;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if ((value > 256) || (value < 0)) {
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
size = (byte)(value - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe byte[] GetBytes()
|
|
||||||
{
|
|
||||||
byte[] ret = new byte[16];
|
|
||||||
fixed (M128* vptr = &data)
|
|
||||||
{
|
|
||||||
byte* bptr = (byte*)vptr;
|
|
||||||
for (int i = 0; i < 15; i++) {
|
|
||||||
ret[i] = *bptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="DataSegment"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.HighPerformance;
|
|
||||||
using StgSharp.HighPerformance;
|
|
||||||
using StgSharp.Internal.Intrinsic;
|
|
||||||
|
|
||||||
using StgSharp.Mathematics;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = World.ssdSegmentLength * 16)]
|
|
||||||
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
|
|
||||||
{
|
|
||||||
|
|
||||||
[FieldOffset(16)] public fixed byte Data[16 * (World.ssdSegmentLength - 1)];
|
|
||||||
[FieldOffset(12)] public int DataHash;
|
|
||||||
[FieldOffset(8)] public int PreviousHash;
|
|
||||||
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
|
|
||||||
|
|
||||||
public SSDSegment(int previousHash)
|
|
||||||
{
|
|
||||||
this.PreviousHash = previousHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte this[int index]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
|
||||||
throw new IndexOutOfRangeException();
|
|
||||||
}
|
|
||||||
return Data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
|
||||||
throw new IndexOutOfRangeException();
|
|
||||||
}
|
|
||||||
Data[index] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ID
|
|
||||||
{
|
|
||||||
get { return Head.globalID; }
|
|
||||||
set { Head.globalID = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public short Size => Head.size;
|
|
||||||
|
|
||||||
public void FillRandomBytes(int begin)
|
|
||||||
{
|
|
||||||
if (begin > 255) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = begin; i < 255; i++) {
|
|
||||||
Data[i] = Scalar.Random<byte>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SSDSegment FromStream(byte[] stream)
|
|
||||||
{
|
|
||||||
if (stream.Length != 16 * World.ssdSegmentLength) {
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
|
||||||
SSDSegment ret = new SSDSegment();
|
|
||||||
fixed (byte* bptr = stream)
|
|
||||||
{
|
|
||||||
ret.Head.data = *(M128*)bptr;
|
|
||||||
for (int i = 1; i < World.ssdSegmentLength; i++) {
|
|
||||||
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] GetBytes()
|
|
||||||
{
|
|
||||||
byte[] ret = new byte[16 * World.ssdSegmentLength];
|
|
||||||
fixed (M128* mptr = &Head.data)
|
|
||||||
{
|
|
||||||
fixed (byte* aptr = ret)
|
|
||||||
{
|
|
||||||
Vector4* vsptr = (Vector4*)mptr;
|
|
||||||
Vector4* vtptr = (Vector4*)aptr;
|
|
||||||
for (int i = 0; i < 18; i++) {
|
|
||||||
*(vtptr + i) = *(vsptr + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetDataHash()
|
|
||||||
{
|
|
||||||
Vector4 v = Vector4.One;
|
|
||||||
fixed (M128* mptr = &Head.data)
|
|
||||||
{
|
|
||||||
Vector4* vptr = (Vector4*)mptr;
|
|
||||||
for (int i = 0; i < World.ssdSegmentLength - 1; i += 1) {
|
|
||||||
v += (*vptr) * 31;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
M128 m = new M128(v);
|
|
||||||
DataHash = m.Vec.GetHashCode();
|
|
||||||
return DataHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
int ret = 17;
|
|
||||||
fixed (M128* mptr = &Head.data)
|
|
||||||
{
|
|
||||||
Vector4* vptr = (Vector4*)mptr;
|
|
||||||
for (int i = 0; i < World.ssdSegmentLength; i++) {
|
|
||||||
ret = (ret + (*vptr).GetHashCode()) * 31;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe T ReadData<T>(int index) where T: unmanaged
|
|
||||||
{
|
|
||||||
fixed (byte* bptr = Data)
|
|
||||||
{
|
|
||||||
T* tptr = (T*)bptr;
|
|
||||||
return *(tptr + index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void WriteData<T>(int index, T value) where T: unmanaged
|
|
||||||
{
|
|
||||||
fixed (byte* bptr = Data)
|
|
||||||
{
|
|
||||||
T* tptr = (T*)bptr;
|
|
||||||
*(tptr + index) = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int IComparable<int>.CompareTo(int other)
|
|
||||||
{
|
|
||||||
return ID.CompareTo(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
|
|
||||||
{
|
|
||||||
return ID.CompareTo(other.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="SSD"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Internal.FileIO;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
public partial class SSD
|
|
||||||
{
|
|
||||||
|
|
||||||
private Dictionary<string, SSDraw> fileList;
|
|
||||||
|
|
||||||
private FileStream file;
|
|
||||||
private SSDrawHead head;
|
|
||||||
|
|
||||||
public SSD()
|
|
||||||
{
|
|
||||||
fileList = new Dictionary<string, SSDraw>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SSD(FileStream fileStream)
|
|
||||||
{
|
|
||||||
fileList = new Dictionary<string, SSDraw>();
|
|
||||||
file = fileStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SSD FromFile(string fileRoute)
|
|
||||||
{
|
|
||||||
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="SSDVirtualFolder"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Internal.FileIO;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
public class SSDFolder : ISSDSerializable
|
|
||||||
{
|
|
||||||
|
|
||||||
internal Dictionary<string, SSDFolder> folders;
|
|
||||||
internal int _folderID;
|
|
||||||
internal string _name;
|
|
||||||
|
|
||||||
internal SSDFolder()
|
|
||||||
{
|
|
||||||
folders = new Dictionary<string, SSDFolder>();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal SSDFolder(string name)
|
|
||||||
{
|
|
||||||
if (name == "root") {
|
|
||||||
throw new ArgumentException(
|
|
||||||
"Name cannot be root," + "it is preserved for root file indexer.");
|
|
||||||
}
|
|
||||||
if (name == "default") {
|
|
||||||
throw new ArgumentException(
|
|
||||||
"Name cannot be default," + "it is preserved for default file id provider.");
|
|
||||||
}
|
|
||||||
_name = name;
|
|
||||||
folders = new Dictionary<string, SSDFolder>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
|
||||||
|
|
||||||
public void FromBytes(byte[] stream)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO TOUGH TO Get Bytes from virtual folders
|
|
||||||
public byte[] GetBytes()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Define"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A class contains a sets of methods to serialize several types
|
|
||||||
/// </summary>
|
|
||||||
public static partial class Serializer { }
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="ISSDSerializable"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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.Internal
|
|
||||||
{
|
|
||||||
public interface ISSDSerializable
|
|
||||||
{
|
|
||||||
|
|
||||||
public SerializableTypeCode SSDTypeCode { get; }
|
|
||||||
|
|
||||||
public byte[] GetBytes();
|
|
||||||
|
|
||||||
internal void FromBytes(byte[] stream);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SerializableTypeCode
|
|
||||||
{
|
|
||||||
|
|
||||||
Unknown = 0,
|
|
||||||
IndexTable = 1,
|
|
||||||
PixelImage = 2,
|
|
||||||
VectorImage = 3,
|
|
||||||
Audio = 4,
|
|
||||||
Shader = 5,
|
|
||||||
Text = 6,
|
|
||||||
RawData = 7,
|
|
||||||
VirtualFolder = int.MaxValue,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static partial class Serializer
|
|
||||||
{
|
|
||||||
|
|
||||||
public static T Deserialize<T>(byte[] stream) where T: ISSDSerializable
|
|
||||||
{
|
|
||||||
T serializableObject = Activator.CreateInstance<T>();
|
|
||||||
serializableObject.FromBytes(stream);
|
|
||||||
return serializableObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetNameTail(SerializableTypeCode typeCode)
|
|
||||||
{
|
|
||||||
switch (typeCode)
|
|
||||||
{
|
|
||||||
case SerializableTypeCode.IndexTable:
|
|
||||||
return "_idt";
|
|
||||||
case SerializableTypeCode.PixelImage:
|
|
||||||
return "_pim";
|
|
||||||
case SerializableTypeCode.VectorImage:
|
|
||||||
return "_vim";
|
|
||||||
case SerializableTypeCode.Audio:
|
|
||||||
return "_wav";
|
|
||||||
case SerializableTypeCode.Shader:
|
|
||||||
return "_gls";
|
|
||||||
case SerializableTypeCode.Text:
|
|
||||||
return "_txt";
|
|
||||||
case SerializableTypeCode.RawData:
|
|
||||||
return "_raw";
|
|
||||||
case SerializableTypeCode.VirtualFolder:
|
|
||||||
return "_fod";
|
|
||||||
default:
|
|
||||||
throw new ArgumentException("Unknown file type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
|
||||||
{
|
|
||||||
return serializableObject.GetBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="CoordinationBase"
|
// file="CoordinationBase"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="PlainCoordinate"
|
// file="PlainCoordinate"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="SpaceCoordinate"
|
// file="SpaceCoordinate"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="GeometryOperation"
|
// file="GeometryOperation"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.Timing;
|
using StgSharp.Timing;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IGeometry"
|
// file="IGeometry"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IInstancing"
|
// file="IInstancing"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IInstancingBuffer"
|
// file="IInstancingBuffer"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="GeometryOperation"
|
// file="GeometryOperation"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IPlainEntity"
|
// file="IPlainEntity"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ParticleOnPlain"
|
// file="ParticleOnPlain"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="PlainGeometry"
|
// file="PlainGeometry"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="PlainInstancingBuffer"
|
// file="PlainInstancingBuffer"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Parallelogram"
|
// file="Parallelogram"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Plain"
|
// file="Plain"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Polygon4"
|
// file="Polygon4"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
@@ -51,7 +51,9 @@ namespace StgSharp.Geometries
|
|||||||
vertexMat = new Vec4[4];
|
vertexMat = new Vec4[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Polygon4(Vec4[] rawCoord)
|
internal Polygon4(
|
||||||
|
Vec4[] rawCoord
|
||||||
|
)
|
||||||
: base(PlainCoordinate.StandardPlainCoordination)
|
: base(PlainCoordinate.StandardPlainCoordination)
|
||||||
{
|
{
|
||||||
if (rawCoord.Length != 4) {
|
if (rawCoord.Length != 4) {
|
||||||
@@ -60,7 +62,12 @@ namespace StgSharp.Geometries
|
|||||||
vertexMat = rawCoord;
|
vertexMat = rawCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polygon4(Point topLeft, Point topRight, Point bottomRight, Point bottomLeft)
|
public Polygon4(
|
||||||
|
Point topLeft,
|
||||||
|
Point topRight,
|
||||||
|
Point bottomRight,
|
||||||
|
Point bottomLeft
|
||||||
|
)
|
||||||
: base(PlainCoordinate.StandardPlainCoordination)
|
: base(PlainCoordinate.StandardPlainCoordination)
|
||||||
{
|
{
|
||||||
this[0] = topLeft;
|
this[0] = topLeft;
|
||||||
@@ -75,7 +82,8 @@ namespace StgSharp.Geometries
|
|||||||
Point topLeft,
|
Point topLeft,
|
||||||
Point topRight,
|
Point topRight,
|
||||||
Point bottomRight,
|
Point bottomRight,
|
||||||
Point bottomLeft)
|
Point bottomLeft
|
||||||
|
)
|
||||||
: base(coordinate)
|
: base(coordinate)
|
||||||
{
|
{
|
||||||
this[0] = topLeft;
|
this[0] = topLeft;
|
||||||
@@ -84,7 +92,16 @@ namespace StgSharp.Geometries
|
|||||||
this[3] = bottomLeft;
|
this[3] = bottomLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polygon4(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
public Polygon4(
|
||||||
|
float v0x,
|
||||||
|
float v0y,
|
||||||
|
float v1x,
|
||||||
|
float v1y,
|
||||||
|
float v2x,
|
||||||
|
float v2y,
|
||||||
|
float v3x,
|
||||||
|
float v3y
|
||||||
|
)
|
||||||
: base(PlainCoordinate.StandardPlainCoordination)
|
: base(PlainCoordinate.StandardPlainCoordination)
|
||||||
{
|
{
|
||||||
vertexMat = new Vec4[4];
|
vertexMat = new Vec4[4];
|
||||||
@@ -104,7 +121,8 @@ namespace StgSharp.Geometries
|
|||||||
float v2x,
|
float v2x,
|
||||||
float v2y,
|
float v2y,
|
||||||
float v3x,
|
float v3x,
|
||||||
float v3y)
|
float v3y
|
||||||
|
)
|
||||||
: base(coordination)
|
: base(coordination)
|
||||||
{
|
{
|
||||||
vertexMat = new Vec4[4];
|
vertexMat = new Vec4[4];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Polygon5"
|
// file="Polygon5"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Polygon6"
|
// file="Polygon6"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Rectangle"
|
// file="Rectangle"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Triangle"
|
// file="Triangle"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Point"
|
// file="Point"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -43,19 +42,27 @@ namespace StgSharp.Geometries
|
|||||||
[FieldOffset(0)] private Vec3 coord;
|
[FieldOffset(0)] private Vec3 coord;
|
||||||
[FieldOffset(0)] internal Vector4 coordVec;
|
[FieldOffset(0)] internal Vector4 coordVec;
|
||||||
|
|
||||||
internal Point(Vec4 vector)
|
internal Point(
|
||||||
|
Vec4 vector
|
||||||
|
)
|
||||||
{
|
{
|
||||||
coordVec = vector.vec;
|
coordVec = vector.vec;
|
||||||
coordVec.W = 1;
|
coordVec.W = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point(Vec3 coord)
|
public Point(
|
||||||
|
Vec3 coord
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Coord = coord;
|
Coord = coord;
|
||||||
coordVec.W = 1;
|
coordVec.W = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point(float x, float y, float z)
|
public Point(
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float z
|
||||||
|
)
|
||||||
{
|
{
|
||||||
coordVec = new Vector4(x, y, z, 1);
|
coordVec = new Vector4(x, y, z, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="TriangulatedSurface"
|
// file="TriangulatedSurface"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
global using StgSharp.Internal;
|
global using StgSharp.Internal;
|
||||||
global using StgSharp.Internal.Intrinsic;
|
|
||||||
global
|
global
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -34,65 +33,5 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
[assembly: InternalsVisibleTo("StgSharp.Mathematics")]
|
[assembly: InternalsVisibleTo("StgSharp.Mathematics")]
|
||||||
[assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")]
|
[assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")]
|
||||||
|
[assembly: InternalsVisibleTo("StgSharp.Graphics")]
|
||||||
[assembly: InternalsVisibleTo("StgSharpDebug")]
|
[assembly: InternalsVisibleTo("StgSharpDebug")]
|
||||||
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Design",
|
|
||||||
"CA1008:枚举应具有零值",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "type",
|
|
||||||
Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Naming",
|
|
||||||
"CA1715:标识符应具有正确的前缀",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Naming",
|
|
||||||
"CA1715:标识符应具有正确的前缀",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Naming",
|
|
||||||
"CA1715:标识符应具有正确的前缀",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Naming",
|
|
||||||
"CA1715:标识符应具有正确的前缀",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "type",
|
|
||||||
Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Design",
|
|
||||||
"CA1043:将整型或字符串参数用于索引器",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~P:StgSharp.MVVM.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Design",
|
|
||||||
"CA1043:将整型或字符串参数用于索引器",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Performance",
|
|
||||||
"CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewRender`1.Item(System.String)")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Design",
|
|
||||||
"CA1033:接口方法应可由子类型调用",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")]
|
|
||||||
[assembly: SuppressMessage(
|
|
||||||
"Design",
|
|
||||||
"CA1033:接口方法应可由子类型调用",
|
|
||||||
Justification = "<挂起>",
|
|
||||||
Scope = "member",
|
|
||||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")]
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="IGraphicAPIs"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Graphics
|
|
||||||
{
|
|
||||||
public interface IGraphicAPIs
|
|
||||||
{
|
|
||||||
|
|
||||||
public IntPtr GraphicApiPackageHandle { get; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="DefaultLog"
|
// file="DefaultLog"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -25,10 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Graphics.OpenGL;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -47,7 +44,9 @@ namespace StgSharp.Internal
|
|||||||
|
|
||||||
internal static SemaphoreSlim logSyncSemaphore = new(1, 1);
|
internal static SemaphoreSlim logSyncSemaphore = new(1, 1);
|
||||||
|
|
||||||
internal static void InternalAppendLog(string log)
|
internal static void InternalAppendLog(
|
||||||
|
string log
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (!File.Exists(Native.LogPath))
|
if (!File.Exists(Native.LogPath))
|
||||||
{
|
{
|
||||||
@@ -60,7 +59,10 @@ namespace StgSharp.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void InternalWriteLog(string logLine, LogType logType)
|
internal static void InternalWriteLog(
|
||||||
|
string logLine,
|
||||||
|
LogType logType
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (logType < _currentLogLevel) {
|
if (logType < _currentLogLevel) {
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +89,11 @@ namespace StgSharp.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
|
internal static void InternalWriteLog(
|
||||||
|
string beforeTime,
|
||||||
|
string logLine,
|
||||||
|
LogType logType
|
||||||
|
)
|
||||||
{
|
{
|
||||||
logSyncSemaphore.Wait();
|
logSyncSemaphore.Wait();
|
||||||
if (!File.Exists(Native.LogPath))
|
if (!File.Exists(Native.LogPath))
|
||||||
@@ -104,7 +110,9 @@ namespace StgSharp.Internal
|
|||||||
_ = logSyncSemaphore.Release(1);
|
_ = logSyncSemaphore.Release(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetLogLevel(LogType logLevel)
|
internal static void SetLogLevel(
|
||||||
|
LogType logLevel
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_currentLogLevel = logLevel;
|
_currentLogLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="InternalResource"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
internal static class BuiltInShader
|
|
||||||
{
|
|
||||||
|
|
||||||
#region ControllingItemRender
|
|
||||||
|
|
||||||
internal const string ControlItemRenderVertexShader = """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""";
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CollisionTexture
|
|
||||||
|
|
||||||
internal static ReadOnlySpan<byte> CollisionTextureVertexShader => """
|
|
||||||
#version 430 core
|
|
||||||
layout(location = 0) in vec2 localCollisionCoord;
|
|
||||||
layout(location = 1) in vec2 spaceCoord;
|
|
||||||
layout(location = 2) in float rotation;
|
|
||||||
layout(location = 3) in float scaling;
|
|
||||||
|
|
||||||
uniform vec2 target;
|
|
||||||
uniform mat2 projection;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
mat2 scaling = mat2(
|
|
||||||
scaling,0,
|
|
||||||
0,scaling );
|
|
||||||
|
|
||||||
mat2 rotation = mat2(
|
|
||||||
cos(rotation),-sin(rotation),
|
|
||||||
sin(rotation),cos(rotation) );
|
|
||||||
|
|
||||||
vec2 realCoord = (rotation * scaling * localCollisionCoord) + spaceCoord - target;
|
|
||||||
realCoord = projection * realCoord;
|
|
||||||
float dist = distance(realCoord, vec2(0,0));
|
|
||||||
float angle = atan(realCoord.y, realCoord.x);
|
|
||||||
gl_Position = vec4(angle, realCoord.y, dist, 1);
|
|
||||||
}
|
|
||||||
"""u8;
|
|
||||||
|
|
||||||
internal static ReadOnlySpan<byte> CollisionTextureFragmentShader => """
|
|
||||||
#version 430 core
|
|
||||||
out vec4 Color;
|
|
||||||
|
|
||||||
uniform float range;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
float dist = gl_FragCoord.z;
|
|
||||||
if(dist > range)
|
|
||||||
{
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
dist /= range;
|
|
||||||
gl_FragDepth = min(dist, gl_FragDepth);
|
|
||||||
Color = vec4(dist,0,0,1);
|
|
||||||
}
|
|
||||||
"""u8;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,944 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="StructDefine"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Graphics;
|
|
||||||
using StgSharp.Graphics.OpenGL;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
/**/
|
|
||||||
|
|
||||||
namespace StgSharp.Internal
|
|
||||||
{
|
|
||||||
// rename types in style of GLFW
|
|
||||||
|
|
||||||
using GLFWbool = Boolean;
|
|
||||||
|
|
||||||
// strucs defined in GLFW3.h
|
|
||||||
|
|
||||||
#region GLFW3 struct
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct glfwContext
|
|
||||||
{
|
|
||||||
|
|
||||||
private delegate*<byte*> extensionSupported;
|
|
||||||
private delegate*<delegate*<void>, void> getProcAddress;
|
|
||||||
|
|
||||||
/*
|
|
||||||
void (* makeCurrent) (glfwWindow*);
|
|
||||||
void (* swapBuffers) (glfwWindow*);
|
|
||||||
void (* swapInterval) (int);
|
|
||||||
int (* extensionSupported) (const byte*);
|
|
||||||
delegate*<void>(*getProcAddress)(const byte*);
|
|
||||||
void (* destroy) (glfwWindow*);
|
|
||||||
*/
|
|
||||||
|
|
||||||
private delegate*<glfwWindow*> makeCurrent;
|
|
||||||
private delegate*<glfwWindow*> swapBuffer;
|
|
||||||
private delegate*<int> swapInterval;
|
|
||||||
private GLFWbool forward, debug, noerror;
|
|
||||||
|
|
||||||
private int client;
|
|
||||||
private int major, minor, revision;
|
|
||||||
private int profile;
|
|
||||||
private int release;
|
|
||||||
private int robustness;
|
|
||||||
private int source;
|
|
||||||
private IntPtr destroy;
|
|
||||||
|
|
||||||
// PFNGLGETINTEGERVPROC GetIntegerv;
|
|
||||||
private IntPtr GetIntegerv;
|
|
||||||
|
|
||||||
// PFNGLGETSTRINGPROC GetString;
|
|
||||||
private IntPtr GetString;
|
|
||||||
|
|
||||||
// PFNGLGETSTRINGIPROC GetStringi;
|
|
||||||
private IntPtr GetStringi;
|
|
||||||
|
|
||||||
internal struct egl
|
|
||||||
{
|
|
||||||
|
|
||||||
private void* client;
|
|
||||||
|
|
||||||
/*
|
|
||||||
EGLConfig config;
|
|
||||||
EGLContext handle;
|
|
||||||
EGLSurface surface;
|
|
||||||
*/
|
|
||||||
private void* config;
|
|
||||||
private void* handle;
|
|
||||||
private void* surface;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct osmesa
|
|
||||||
{
|
|
||||||
|
|
||||||
private void* buffer;
|
|
||||||
|
|
||||||
// OSMesaContext handle;
|
|
||||||
private void* handle;
|
|
||||||
private int height;
|
|
||||||
|
|
||||||
private int width;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
// GLFW_PLATFORM_CONTEXT_STATE
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct glfwVideomode
|
|
||||||
{
|
|
||||||
/*! The refresh rate, in Hz, of the video mode.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private int refreshRate;
|
|
||||||
/*! The bit depth of the blue channel of the video mode.
|
|
||||||
*/
|
|
||||||
public int blueBits;
|
|
||||||
/*! The bit depth of the green channel of the video mode.
|
|
||||||
*/
|
|
||||||
public int greenBits;
|
|
||||||
/*! The height, in screen coordinates, of the video mode.
|
|
||||||
*/
|
|
||||||
public int height;
|
|
||||||
/*! The bit depth of the red channel of the video mode.
|
|
||||||
*/
|
|
||||||
public int redBits;
|
|
||||||
|
|
||||||
/*! The width, in screen coordinates, of the video mode.
|
|
||||||
*/
|
|
||||||
public int width;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct glfwGammaramp
|
|
||||||
{
|
|
||||||
/*! An array of value describing the response of the blue channel.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private ushort* blue;
|
|
||||||
/*! An array of value describing the response of the green channel.
|
|
||||||
*/
|
|
||||||
private ushort* green;
|
|
||||||
|
|
||||||
/*! An array of value describing the response of the red channel.
|
|
||||||
*/
|
|
||||||
private ushort* red;
|
|
||||||
/*! The number of elements in each array.
|
|
||||||
*/
|
|
||||||
private uint size;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWimage
|
|
||||||
{
|
|
||||||
/*! The pixel _data of this image, arranged left-to-right, top-to-bottom.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private byte* pixels;
|
|
||||||
|
|
||||||
/*! The height, in pixels, of this image.
|
|
||||||
*/
|
|
||||||
private int height;
|
|
||||||
/*! The width, in pixels, of this image.
|
|
||||||
*/
|
|
||||||
private int width;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWgamepadstate
|
|
||||||
{
|
|
||||||
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
|
|
||||||
* or `GLFW_RELEASE`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public fixed byte buttons[15];
|
|
||||||
|
|
||||||
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
|
|
||||||
* to 1.0 inclusive.
|
|
||||||
*/
|
|
||||||
public fixed float axes[6];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWallocator
|
|
||||||
{
|
|
||||||
|
|
||||||
private void* user;
|
|
||||||
|
|
||||||
// GLFWallocatefun allocate;
|
|
||||||
private IntPtr allocate;
|
|
||||||
|
|
||||||
// GLFWdeallocatefun deallocate;
|
|
||||||
private IntPtr deallocate;
|
|
||||||
|
|
||||||
// GLFWreallocatefun reallocate;
|
|
||||||
private IntPtr reallocate;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct glfwMonitor
|
|
||||||
{
|
|
||||||
|
|
||||||
private glfwVideomode* modes;
|
|
||||||
|
|
||||||
private glfwWindow* window;
|
|
||||||
|
|
||||||
private fixed byte name[128];
|
|
||||||
private glfwGammaramp currentRamp;
|
|
||||||
|
|
||||||
private glfwGammaramp originalRamp;
|
|
||||||
private glfwVideomode currentMode;
|
|
||||||
private int modeCount;
|
|
||||||
|
|
||||||
private int width, height;
|
|
||||||
private IntPtr userPointer;
|
|
||||||
|
|
||||||
public glfwMonitor() { }
|
|
||||||
|
|
||||||
public unsafe string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
fixed (byte* cptr = name) {
|
|
||||||
return Marshal.PtrToStringAnsi((IntPtr)cptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal unsafe struct glfwWindow
|
|
||||||
{
|
|
||||||
|
|
||||||
private glfwWindow* next;
|
|
||||||
private void* userPointer;
|
|
||||||
private bool rawMouseMotion;
|
|
||||||
private Callbacks callbacks;
|
|
||||||
|
|
||||||
// Virtual cursor position when cursor is disabled
|
|
||||||
private double virtualCursorPosX, virtualCursorPosY;
|
|
||||||
private int autoIconify;
|
|
||||||
private int cursorMode;
|
|
||||||
private int decorated;
|
|
||||||
private int doublebuffer;
|
|
||||||
private int floating;
|
|
||||||
private int focusOnShow;
|
|
||||||
private int lockKeyMods;
|
|
||||||
private int maxwidth, maxheight;
|
|
||||||
|
|
||||||
private int minwidth, minheight;
|
|
||||||
private int mousePassthrough;
|
|
||||||
private int numer, denom;
|
|
||||||
|
|
||||||
// Window settings and state
|
|
||||||
private int resizable;
|
|
||||||
private int shouldClose;
|
|
||||||
|
|
||||||
private int stickyKeys;
|
|
||||||
private int stickyMouseButtons;
|
|
||||||
private IntPtr cursor; // _GLFWcursor* cursor;
|
|
||||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
|
||||||
private IntPtr monitor; // _GLFWmonitor* monitor;
|
|
||||||
public fixed byte keys[FrameworkConstant.KEY_LAST + 1];
|
|
||||||
public fixed byte mouseButtons[FrameworkConstant.MOUSE_BUTTON_LAST + 1];
|
|
||||||
|
|
||||||
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
|
|
||||||
|
|
||||||
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
|
|
||||||
internal struct Callbacks
|
|
||||||
{
|
|
||||||
|
|
||||||
internal IntPtr character;
|
|
||||||
internal IntPtr charmods;
|
|
||||||
internal IntPtr close;
|
|
||||||
internal IntPtr cursorEnter;
|
|
||||||
internal IntPtr cursorPos;
|
|
||||||
internal IntPtr drop;
|
|
||||||
internal IntPtr fbsize;
|
|
||||||
internal IntPtr focus;
|
|
||||||
internal IntPtr iconify;
|
|
||||||
internal IntPtr key;
|
|
||||||
internal IntPtr maximize;
|
|
||||||
internal IntPtr mouseButton;
|
|
||||||
internal IntPtr pos;
|
|
||||||
internal IntPtr refresh;
|
|
||||||
internal IntPtr scale;
|
|
||||||
internal IntPtr scroll;
|
|
||||||
internal IntPtr size;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct GLFWwindowCallback { }
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct GLFWcursor
|
|
||||||
{
|
|
||||||
|
|
||||||
// GLFWcursor* next;
|
|
||||||
private IntPtr next;
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
// not completed in tranformation
|
|
||||||
// GLFW_PLATFORM_CURSOR_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWerror
|
|
||||||
{
|
|
||||||
//GLFWerror* next;
|
|
||||||
IntPtr next;
|
|
||||||
int code;
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)glConst.GLFW_MESSAGE_SIZE)]
|
|
||||||
byte[] description = new byte[glConst.GLFW_MESSAGE_SIZE];
|
|
||||||
|
|
||||||
public GLFWerror()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWinitconfig
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool hatButtons;
|
|
||||||
|
|
||||||
private int angleType;
|
|
||||||
private int platformID;
|
|
||||||
|
|
||||||
// PFN_vkGetInstanceProcAddr vulkanLoader;
|
|
||||||
private IntPtr vulkanLoader;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWwndconfig
|
|
||||||
{
|
|
||||||
|
|
||||||
private byte* title;
|
|
||||||
|
|
||||||
private GLFWbool autoIconify;
|
|
||||||
private GLFWbool centerCursor;
|
|
||||||
private GLFWbool decorated;
|
|
||||||
private GLFWbool floating;
|
|
||||||
private GLFWbool focused;
|
|
||||||
private GLFWbool focusOnShow;
|
|
||||||
private GLFWbool maximized;
|
|
||||||
private GLFWbool mousePassthrough;
|
|
||||||
private GLFWbool resizable;
|
|
||||||
private GLFWbool scaleToMonitor;
|
|
||||||
private GLFWbool visible;
|
|
||||||
private int height;
|
|
||||||
private int width;
|
|
||||||
|
|
||||||
private int xpos;
|
|
||||||
private int ypos;
|
|
||||||
|
|
||||||
internal Ns ns = new Ns();
|
|
||||||
|
|
||||||
internal Win32 win32 = new Win32();
|
|
||||||
|
|
||||||
internal Wl wl = new Wl();
|
|
||||||
|
|
||||||
internal X11 x11 = new X11();
|
|
||||||
|
|
||||||
public GLFWwndconfig() { }
|
|
||||||
|
|
||||||
internal struct Ns
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool retina = false;
|
|
||||||
public fixed byte frameName[256];
|
|
||||||
|
|
||||||
public Ns() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct X11
|
|
||||||
{
|
|
||||||
|
|
||||||
public fixed byte className[256];
|
|
||||||
public fixed byte instanceName[256];
|
|
||||||
|
|
||||||
public X11() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct Win32
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool keymenu;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct Wl
|
|
||||||
{
|
|
||||||
|
|
||||||
public fixed byte appId[256];
|
|
||||||
|
|
||||||
public Wl() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWctxconfig
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool debug;
|
|
||||||
private GLFWbool forward;
|
|
||||||
private GLFWbool noerror;
|
|
||||||
|
|
||||||
private int client;
|
|
||||||
private int major;
|
|
||||||
private int minor;
|
|
||||||
private int profile;
|
|
||||||
private int release;
|
|
||||||
private int robustness;
|
|
||||||
private int source;
|
|
||||||
|
|
||||||
// glfwWindow* share;
|
|
||||||
private IntPtr share;
|
|
||||||
|
|
||||||
internal Nsgl nsgl = new Nsgl();
|
|
||||||
|
|
||||||
public GLFWctxconfig() { }
|
|
||||||
|
|
||||||
internal struct Nsgl
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool offline;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWfbconfig
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWbool doublebuffer;
|
|
||||||
private GLFWbool sRGB;
|
|
||||||
private GLFWbool stereo;
|
|
||||||
private GLFWbool transparent;
|
|
||||||
|
|
||||||
private int accumAlphaBits;
|
|
||||||
private int accumBlueBits;
|
|
||||||
private int accumGreenBits;
|
|
||||||
private int accumRedBits;
|
|
||||||
private int alphaBits;
|
|
||||||
private int auxBuffers;
|
|
||||||
private int blueBits;
|
|
||||||
private int depthBits;
|
|
||||||
private int greenBits;
|
|
||||||
|
|
||||||
private int redBits;
|
|
||||||
private int samples;
|
|
||||||
private int stencilBits;
|
|
||||||
private uintptr_t handle;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal unsafe struct GLFWlibrary
|
|
||||||
{
|
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = FrameworkConstant.JOYSTICK_LAST + 1)]
|
|
||||||
private GLFWjoystick[] joysticks = new GLFWjoystick[FrameworkConstant.JOYSTICK_LAST + 1];
|
|
||||||
|
|
||||||
private GLFWallocator allocator;
|
|
||||||
|
|
||||||
private GLFWbool initialized;
|
|
||||||
|
|
||||||
private GLFWbool joysticksInitialized;
|
|
||||||
private GLFWls contextSlot;
|
|
||||||
|
|
||||||
private GLFWls errorSlot;
|
|
||||||
private GLFWmutex errorLock;
|
|
||||||
|
|
||||||
private GLFWplatform platform;
|
|
||||||
|
|
||||||
private int mappingCount;
|
|
||||||
|
|
||||||
private int monitorCount;
|
|
||||||
|
|
||||||
// GLFWcursor* cursorListHead;
|
|
||||||
private IntPtr cursorListHead;
|
|
||||||
|
|
||||||
// GLFWerror* errorListHead;
|
|
||||||
private IntPtr errorListHead;
|
|
||||||
|
|
||||||
// GLFWmapping* mappings;
|
|
||||||
private IntPtr mappings;
|
|
||||||
|
|
||||||
// GLFWmonitor** monitors;
|
|
||||||
private IntPtr monitors;
|
|
||||||
|
|
||||||
// glfwWindow* windowListHead;
|
|
||||||
private IntPtr windowListHead;
|
|
||||||
|
|
||||||
internal Callbacks callbacks = new Callbacks();
|
|
||||||
|
|
||||||
internal Egl egl = new Egl();
|
|
||||||
|
|
||||||
internal Hints hints = new Hints();
|
|
||||||
|
|
||||||
internal Osmesa osmesa = new Osmesa();
|
|
||||||
|
|
||||||
public GLFWlibrary() { }
|
|
||||||
|
|
||||||
internal unsafe struct Hints
|
|
||||||
{
|
|
||||||
|
|
||||||
private GLFWctxconfig context;
|
|
||||||
private GLFWfbconfig framebuffer;
|
|
||||||
|
|
||||||
private GLFWinitconfig init;
|
|
||||||
private GLFWwndconfig window;
|
|
||||||
private int refreshRate;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal unsafe struct timer
|
|
||||||
{
|
|
||||||
|
|
||||||
private ulong offset;
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
|
|
||||||
// not transformed function defination
|
|
||||||
// GLFW_PLATFORM_LIBRARY_TIMER_STATE
|
|
||||||
}
|
|
||||||
|
|
||||||
internal unsafe struct Egl
|
|
||||||
{
|
|
||||||
|
|
||||||
internal void* display;
|
|
||||||
|
|
||||||
internal void* handle;
|
|
||||||
|
|
||||||
internal bool ANGLE_platform_angle;
|
|
||||||
internal bool ANGLE_platform_angle_d3d;
|
|
||||||
internal bool ANGLE_platform_angle_metal;
|
|
||||||
internal bool ANGLE_platform_angle_opengl;
|
|
||||||
internal bool ANGLE_platform_angle_vulkan;
|
|
||||||
internal bool EXT_client_extensions;
|
|
||||||
internal bool EXT_platform_base;
|
|
||||||
internal bool EXT_platform_wayland;
|
|
||||||
internal bool EXT_platform_x11;
|
|
||||||
internal bool EXT_present_opaque;
|
|
||||||
internal bool KHR_colorSpace;
|
|
||||||
internal bool KHR_context_flush_control;
|
|
||||||
|
|
||||||
internal bool KHR_create_context;
|
|
||||||
internal bool KHR_create_context_no_error;
|
|
||||||
internal bool KHR_get_all_proc_addresses;
|
|
||||||
internal bool prefix;
|
|
||||||
internal int major, minor;
|
|
||||||
|
|
||||||
internal int platform;
|
|
||||||
internal IntPtr BindAPI;
|
|
||||||
internal IntPtr CreateContext;
|
|
||||||
internal IntPtr CreatePlatformWindowSurfaceEXT;
|
|
||||||
internal IntPtr CreateWindowSurface;
|
|
||||||
internal IntPtr DestroyContext;
|
|
||||||
internal IntPtr DestroySurface;
|
|
||||||
|
|
||||||
internal IntPtr GetConfigAttrib;
|
|
||||||
internal IntPtr GetConfigs;
|
|
||||||
internal IntPtr GetDisplay;
|
|
||||||
internal IntPtr GetError;
|
|
||||||
|
|
||||||
internal IntPtr GetPlatformDisplayEXT;
|
|
||||||
internal IntPtr GetProcAddress;
|
|
||||||
internal IntPtr Initialize;
|
|
||||||
internal IntPtr MakeCurrent;
|
|
||||||
internal IntPtr QueryString;
|
|
||||||
internal IntPtr SwapBuffers;
|
|
||||||
internal IntPtr SwapInterval;
|
|
||||||
internal IntPtr Terminate;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal unsafe struct Osmesa
|
|
||||||
{
|
|
||||||
|
|
||||||
private void* handle;
|
|
||||||
|
|
||||||
private IntPtr CreateContextAttribs;
|
|
||||||
|
|
||||||
private IntPtr CreateContextExt;
|
|
||||||
private IntPtr DestroyContext;
|
|
||||||
private IntPtr GetColorBuffer;
|
|
||||||
private IntPtr GetDepthBuffer;
|
|
||||||
private IntPtr GetProcAddress;
|
|
||||||
private IntPtr MakeCurrent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal unsafe struct vk
|
|
||||||
{
|
|
||||||
|
|
||||||
private void* handle;
|
|
||||||
|
|
||||||
private GLFWbool available;
|
|
||||||
private GLFWbool EXT_metal_surface;
|
|
||||||
private GLFWbool KHR_surface;
|
|
||||||
private GLFWbool KHR_wayland_surface;
|
|
||||||
private GLFWbool KHR_win32_surface;
|
|
||||||
private GLFWbool KHR_xcb_surface;
|
|
||||||
private GLFWbool KHR_xlib_surface;
|
|
||||||
private GLFWbool MVK_macos_surface;
|
|
||||||
private IntPtr GetInstanceProcAddr;
|
|
||||||
private fixed ulong extensions[2];
|
|
||||||
|
|
||||||
public vk() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal unsafe struct Callbacks
|
|
||||||
{
|
|
||||||
|
|
||||||
private IntPtr joystick;
|
|
||||||
|
|
||||||
private IntPtr monitor;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWmapelement
|
|
||||||
{
|
|
||||||
|
|
||||||
private byte index;
|
|
||||||
|
|
||||||
private byte type;
|
|
||||||
|
|
||||||
private sbyte axisOffset;
|
|
||||||
private sbyte axisScale;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWmapping
|
|
||||||
{
|
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
|
||||||
private GLFWmapelement[] axes = new GLFWmapelement[6];
|
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
|
|
||||||
private GLFWmapelement[] buttons = new GLFWmapelement[15];
|
|
||||||
private fixed byte guid[33];
|
|
||||||
|
|
||||||
private fixed byte name[128];
|
|
||||||
|
|
||||||
public GLFWmapping() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWjoystick
|
|
||||||
{
|
|
||||||
|
|
||||||
private float* axes;
|
|
||||||
private byte* buttons;
|
|
||||||
private byte* hats;
|
|
||||||
private void* userPointer;
|
|
||||||
private fixed byte guid[33];
|
|
||||||
private fixed byte name[128];
|
|
||||||
|
|
||||||
private GLFWbool allocated;
|
|
||||||
private GLFWbool connected;
|
|
||||||
private int axisCount;
|
|
||||||
private int buttonCount;
|
|
||||||
private int hatCount;
|
|
||||||
|
|
||||||
// GLFWmapping* mapping;
|
|
||||||
private IntPtr mapping;
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
// not completed in transforming
|
|
||||||
// GLFW_PLATFORM_JOYSTICK_STATE;
|
|
||||||
|
|
||||||
public GLFWjoystick() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWls
|
|
||||||
{
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
|
|
||||||
// GLFW_PLATFORM_TLS_STATE
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWplatform
|
|
||||||
{
|
|
||||||
|
|
||||||
private int platformID;
|
|
||||||
|
|
||||||
// init
|
|
||||||
// GLFWbool(*init)(void);
|
|
||||||
private IntPtr init;
|
|
||||||
|
|
||||||
// void (* terminate) (void);
|
|
||||||
private IntPtr terminate;
|
|
||||||
internal IntPtr createCursor;
|
|
||||||
internal IntPtr createStandardCursor;
|
|
||||||
|
|
||||||
// window
|
|
||||||
internal IntPtr createWindow;
|
|
||||||
internal IntPtr destroyCursor;
|
|
||||||
|
|
||||||
internal IntPtr destroyWindow;
|
|
||||||
internal IntPtr focusWindow;
|
|
||||||
internal IntPtr framebufferTransparent;
|
|
||||||
|
|
||||||
// monitor
|
|
||||||
internal IntPtr freeMonitor;
|
|
||||||
internal IntPtr getClipboardString;
|
|
||||||
|
|
||||||
internal IntPtr getEGLNativeDisplay;
|
|
||||||
internal IntPtr getEGLNativeWindow;
|
|
||||||
|
|
||||||
// EGL
|
|
||||||
// EGLenum(*getEGLPlatform)(EGLint**);
|
|
||||||
// EGLNativeDisplayType(*getEGLNativeDisplay)(void);
|
|
||||||
// EGLNativeWindowType(*getEGLNativeWindow)(glfwWindow*);
|
|
||||||
internal IntPtr getEGLPlatform;
|
|
||||||
internal IntPtr getFramebufferSize;
|
|
||||||
internal IntPtr getGammaRamp;
|
|
||||||
internal IntPtr getKeyScancode;
|
|
||||||
internal IntPtr getMappingName;
|
|
||||||
internal IntPtr getMonitorContentScale;
|
|
||||||
|
|
||||||
internal IntPtr getMonitorPos;
|
|
||||||
internal IntPtr getMonitorWorkarea;
|
|
||||||
|
|
||||||
// vulkan
|
|
||||||
// void (* getRequiredInstanceExtensions) (byte**);
|
|
||||||
// GLFWbool(*getPhysicalDevicePresentationSupport)(VkInstance, VkPhysicalDevice, uint32_t);
|
|
||||||
// VkResult(*createWindowSurface)(VkInstance, glfwWindow*,const VkAllocationCallbacks*, VkSurfaceKHR*);
|
|
||||||
internal IntPtr getRequiredInstanceExtensions;
|
|
||||||
internal IntPtr getScancodeName;
|
|
||||||
internal IntPtr getVideoMode;
|
|
||||||
internal IntPtr getVideoModes;
|
|
||||||
internal IntPtr getWindowContentScale;
|
|
||||||
internal IntPtr getWindowFrameSize;
|
|
||||||
internal IntPtr getWindowOpacity;
|
|
||||||
internal IntPtr getWindowPos;
|
|
||||||
internal IntPtr getWindowSize;
|
|
||||||
internal IntPtr GLFWwindow;
|
|
||||||
internal IntPtr hideWindow;
|
|
||||||
internal IntPtr iconifyWindow;
|
|
||||||
internal IntPtr initJoysticks;
|
|
||||||
internal IntPtr maximizeWindow;
|
|
||||||
internal IntPtr pollEvents;
|
|
||||||
internal IntPtr pollJoystick;
|
|
||||||
internal IntPtr postEmptyEvent;
|
|
||||||
internal IntPtr rawMouseMotionSupported;
|
|
||||||
internal IntPtr requestWindowAttention;
|
|
||||||
internal IntPtr restoreWindow;
|
|
||||||
internal IntPtr setClipboardString;
|
|
||||||
internal IntPtr setCursor;
|
|
||||||
internal IntPtr setCursorMode;
|
|
||||||
|
|
||||||
#region input
|
|
||||||
|
|
||||||
/* void (* getCursorPos) (glfwWindow*, double*, double*);
|
|
||||||
void (* setCursorPos) (glfwWindow*, double, double);
|
|
||||||
void (* setCursorMode) (glfwWindow*, int);
|
|
||||||
void (* setRawMouseMotion) (glfwWindow*, GLFWbool);
|
|
||||||
GLFWbool(*rawMouseMotionSupported)(void);
|
|
||||||
GLFWbool(*createCursor)(GLFWcursor*,const GLFWimage*,int,int);
|
|
||||||
GLFWbool(*createStandardCursor)(GLFWcursor*, int);
|
|
||||||
void (* destroyCursor) (GLFWcursor*);
|
|
||||||
void (* setCursor) (glfwWindow*, GLFWcursor*);
|
|
||||||
const byte* (*getScancodeName)(int);
|
|
||||||
int (* getKeyScancode) (int);
|
|
||||||
void (* setClipboardString) (const byte*);
|
|
||||||
const byte* (*getClipboardString)(void);
|
|
||||||
GLFWbool(*initJoysticks)(void);
|
|
||||||
void (* terminateJoysticks) (void);
|
|
||||||
GLFWbool(*pollJoystick)(GLFWjoystick*, int);
|
|
||||||
const byte* (*getMappingName)(void);
|
|
||||||
void (* updateGamepadGUID) (byte*);
|
|
||||||
// monitor
|
|
||||||
void (* freeMonitor) (GLFWmonitor*);
|
|
||||||
void (* getMonitorPos) (GLFWmonitor*, int*, int*);
|
|
||||||
void (* getMonitorContentScale) (GLFWmonitor*, float*, float*);
|
|
||||||
void (* getMonitorWorkarea) (GLFWmonitor*, int*, int*, int*, int*);
|
|
||||||
glfwVideomode* (* getVideoModes) (GLFWmonitor*, int*);
|
|
||||||
void (* getVideoMode) (GLFWmonitor*, glfwVideomode*);
|
|
||||||
GLFWbool(*getGammaRamp)(GLFWmonitor*, glfwGammaramp*);
|
|
||||||
void (* setGammaRamp) (GLFWmonitor*,const glfwGammaramp*);
|
|
||||||
// window
|
|
||||||
GLFWbool(*createWindow)(glfwWindow*,const GLFWwndconfig*,const GLFWctxconfig*,const GLFWfbconfig*);
|
|
||||||
void (* destroyWindow) (glfwWindow*);
|
|
||||||
void (* setWindowTitle) (glfwWindow*,const byte*);
|
|
||||||
void (* setWindowIcon) (glfwWindow*, int,const GLFWimage*);
|
|
||||||
void (* getWindowPos) (glfwWindow*, int*, int*);
|
|
||||||
void (* setWindowPos) (glfwWindow*, int, int);
|
|
||||||
void (* getWindowSize) (glfwWindow*, int*, int*);
|
|
||||||
void (* setWindowSize) (glfwWindow*, int, int);
|
|
||||||
void (* setWindowSizeLimits) (glfwWindow*, int, int, int, int);
|
|
||||||
void (* setWindowAspectRatio) (glfwWindow*, int, int);
|
|
||||||
void (* getFramebufferSize) (glfwWindow*, int*, int*);
|
|
||||||
void (* getWindowFrameSize) (glfwWindow*, int*, int*, int*, int*);
|
|
||||||
void (* getWindowContentScale) (glfwWindow*, float*, float*);
|
|
||||||
void (* iconifyWindow) (glfwWindow*);
|
|
||||||
void (* restoreWindow) (glfwWindow*);
|
|
||||||
void (* maximizeWindow) (glfwWindow*);
|
|
||||||
void (* showWindow) (glfwWindow*);
|
|
||||||
void (* hideWindow) (glfwWindow*);
|
|
||||||
void (* requestWindowAttention) (glfwWindow*);
|
|
||||||
void (* focusWindow) (glfwWindow*);
|
|
||||||
void (* setWindowMonitor) (glfwWindow*, GLFWmonitor*, int, int, int, int, int);
|
|
||||||
GLFWbool(*windowFocused)(glfwWindow*);
|
|
||||||
GLFWbool(*windowIconified)(glfwWindow*);
|
|
||||||
GLFWbool(*windowVisible)(glfwWindow*);
|
|
||||||
GLFWbool(*windowMaximized)(glfwWindow*);
|
|
||||||
GLFWbool(*windowHovered)(glfwWindow*);
|
|
||||||
GLFWbool(*framebufferTransparent)(glfwWindow*);
|
|
||||||
float (* getWindowOpacity) (glfwWindow*);
|
|
||||||
void (* setWindowResizable) (glfwWindow*, GLFWbool);
|
|
||||||
void (* setWindowDecorated) (glfwWindow*, GLFWbool);
|
|
||||||
void (* setWindowFloating) (glfwWindow*, GLFWbool);
|
|
||||||
void (* setWindowOpacity) (glfwWindow*, float);
|
|
||||||
void (* setWindowMousePassthrough) (glfwWindow*, GLFWbool);
|
|
||||||
void (* pollEvents) (void);
|
|
||||||
void (* waitEvents) (void);
|
|
||||||
void (* waitEventsTimeout) (double);
|
|
||||||
void (* postEmptyEvent) (void);
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
internal IntPtr setCursorPos;
|
|
||||||
internal IntPtr setGammaRamp;
|
|
||||||
internal IntPtr setRawMouseMotion;
|
|
||||||
internal IntPtr setWindowAspectRatio;
|
|
||||||
internal IntPtr setWindowDecorated;
|
|
||||||
internal IntPtr setWindowFloating;
|
|
||||||
internal IntPtr setWindowIcon;
|
|
||||||
internal IntPtr setWindowMonitor;
|
|
||||||
internal IntPtr setWindowMousePassthrough;
|
|
||||||
internal IntPtr setWindowOpacity;
|
|
||||||
internal IntPtr setWindowPos;
|
|
||||||
internal IntPtr setWindowResizable;
|
|
||||||
internal IntPtr setWindowSize;
|
|
||||||
internal IntPtr setWindowSizeLimits;
|
|
||||||
internal IntPtr setWindowTitle;
|
|
||||||
internal IntPtr showWindow;
|
|
||||||
internal IntPtr terminateJoysticks;
|
|
||||||
internal IntPtr updateGamepadGUID;
|
|
||||||
|
|
||||||
internal IntPtr VkPhysicalDevice;
|
|
||||||
internal IntPtr waitEvents;
|
|
||||||
internal IntPtr waitEventsTimeout;
|
|
||||||
internal IntPtr windowFocused;
|
|
||||||
internal IntPtr windowHovered;
|
|
||||||
internal IntPtr windowIconified;
|
|
||||||
internal IntPtr windowMaximized;
|
|
||||||
internal IntPtr windowVisible;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public unsafe struct GLFWmutex
|
|
||||||
{
|
|
||||||
|
|
||||||
// This is defined in platform.h
|
|
||||||
// GLFW_PLATFORM_MUTEX_STATE
|
|
||||||
}
|
|
||||||
|
|
||||||
// public unsafe struct VkAllocationCallbacks { }
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal unsafe struct VkExtensionProperties
|
|
||||||
{
|
|
||||||
|
|
||||||
private fixed byte extensionName[256];
|
|
||||||
private uint specVersion;
|
|
||||||
|
|
||||||
public VkExtensionProperties() { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal unsafe struct GLFWerror
|
|
||||||
{
|
|
||||||
IntPtr next;
|
|
||||||
int code;
|
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
|
|
||||||
byte[] description = new byte[1024];
|
|
||||||
|
|
||||||
public GLFWerror()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
|
||||||
public struct uintptr_t
|
|
||||||
{
|
|
||||||
|
|
||||||
[FieldOffset(0)]
|
|
||||||
private long part1;
|
|
||||||
|
|
||||||
[FieldOffset(8)]
|
|
||||||
private long part2;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion GLFW3 struct
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**/
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="OpenGLControllingItemRender"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.Graphics.OpenGL;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp.MVVM
|
|
||||||
{
|
|
||||||
public class OpenGLControllingItemRender : glRender
|
|
||||||
{
|
|
||||||
|
|
||||||
public override bool IsContextSharable => true;
|
|
||||||
|
|
||||||
protected override void CustomizeDeinit()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void CustomizeInit()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,7 @@ using StgSharp.Controlling.UsrActivity;
|
|||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Graphics.OpenGL;
|
using StgSharp.Graphics.OpenGL;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.MVVM;
|
using StgSharp.MVVM;
|
||||||
using StgSharp.MVVM.ViewModel;
|
using StgSharp.MVVM.ViewModel;
|
||||||
using StgSharp.Threading;
|
using StgSharp.Threading;
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="ElementType"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
#pragma warning disable CA1028
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
|
||||||
{
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 4)]
|
|
||||||
public struct MatrixElementType
|
|
||||||
{
|
|
||||||
|
|
||||||
public static readonly MatrixElementType F32 = new(0x03000004);
|
|
||||||
public static readonly MatrixElementType F64 = new(0x03000008);
|
|
||||||
public static readonly MatrixElementType I08 = new(0x0100001);
|
|
||||||
public static readonly MatrixElementType I16 = new(0x0100002);
|
|
||||||
public static readonly MatrixElementType I32 = new(0x0100004);
|
|
||||||
public static readonly MatrixElementType I64 = new(0x0100008);
|
|
||||||
public static readonly MatrixElementType U08 = new(0x0200001);
|
|
||||||
public static readonly MatrixElementType U16 = new(0x0200002);
|
|
||||||
public static readonly MatrixElementType U32 = new(0x0200004);
|
|
||||||
public static readonly MatrixElementType U64 = new(0x0200008);
|
|
||||||
|
|
||||||
[FieldOffset(0)] internal readonly int Mask;
|
|
||||||
[FieldOffset(3)] public readonly MatrixElementTypeGroup Group;
|
|
||||||
|
|
||||||
[FieldOffset(0)] public readonly ushort Size;
|
|
||||||
|
|
||||||
private MatrixElementType(
|
|
||||||
int mask
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Unsafe.SkipInit(out this);
|
|
||||||
Unsafe.SkipInit(out Size);
|
|
||||||
Unsafe.SkipInit(out Group);
|
|
||||||
this.Mask = mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum MatrixElementTypeGroup : byte
|
|
||||||
{
|
|
||||||
|
|
||||||
None = 0,
|
|
||||||
Singed = 1,
|
|
||||||
Unsigned = 2,
|
|
||||||
Float = 3,
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma warning restore CA1028
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ using StgSharp.Graphics.OpenGL;
|
|||||||
using StgSharp.Internal;
|
using StgSharp.Internal;
|
||||||
|
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using StgSharp.MVVM;
|
using StgSharp.MVVM;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -115,6 +115,10 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Graphics\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
+99
-87
@@ -1,87 +1,99 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ColumnSet2"
|
// file="ColumnSet2"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp;
|
using StgSharp;
|
||||||
using StgSharp.Internal.Intrinsic;
|
|
||||||
|
using System;
|
||||||
using System;
|
using System.Numerics;
|
||||||
using System.Numerics;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Text;
|
||||||
using System.Text;
|
|
||||||
|
namespace StgSharp.Mathematics.Internal
|
||||||
namespace StgSharp.Internal.Intrinsic
|
{
|
||||||
{
|
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
internal struct ColumnSet2 : IEquatable<ColumnSet2>
|
||||||
internal struct ColumnSet2 : IEquatable<ColumnSet2>
|
{
|
||||||
{
|
|
||||||
|
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
[FieldOffset(4 * sizeof(float))] internal float m01;
|
||||||
[FieldOffset(4 * sizeof(float))] internal float m01;
|
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
[FieldOffset(5 * sizeof(float))] internal float m11;
|
||||||
[FieldOffset(5 * sizeof(float))] internal float m11;
|
[FieldOffset(2 * sizeof(float))] internal float m20;
|
||||||
[FieldOffset(2 * sizeof(float))] internal float m20;
|
[FieldOffset(6 * sizeof(float))] internal float m21;
|
||||||
[FieldOffset(6 * sizeof(float))] internal float m21;
|
[FieldOffset(3 * sizeof(float))] internal float m30;
|
||||||
[FieldOffset(3 * sizeof(float))] internal float m30;
|
[FieldOffset(7 * sizeof(float))] internal float m31;
|
||||||
[FieldOffset(7 * sizeof(float))] internal float m31;
|
|
||||||
|
[FieldOffset(0)] internal Vector4 colum0;
|
||||||
[FieldOffset(0)] internal Vector4 colum0;
|
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
|
||||||
|
internal ColumnSet2(
|
||||||
internal ColumnSet2(Vector4 c0, Vector4 c1)
|
Vector4 c0,
|
||||||
{
|
Vector4 c1
|
||||||
Unsafe.SkipInit(out this);
|
)
|
||||||
colum0 = c0;
|
{
|
||||||
colum1 = c1;
|
Unsafe.SkipInit(out this);
|
||||||
}
|
colum0 = c0;
|
||||||
|
colum1 = c1;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
}
|
||||||
public override bool Equals(object? obj)
|
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
return (obj is ColumnSet2 mat) && Equals(mat);
|
public override bool Equals(
|
||||||
}
|
object? obj
|
||||||
|
)
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
{
|
||||||
public bool Equals(ColumnSet2 other)
|
return (obj is ColumnSet2 mat) && Equals(mat);
|
||||||
{
|
}
|
||||||
return colum0.Equals(other.colum0) && colum1.Equals(other.colum1);
|
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool Equals(
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
ColumnSet2 other
|
||||||
public static bool operator !=(ColumnSet2 left, ColumnSet2 right)
|
)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return colum0.Equals(other.colum0) && colum1.Equals(other.colum1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(ColumnSet2 left, ColumnSet2 right)
|
public static bool operator !=(
|
||||||
{
|
ColumnSet2 left,
|
||||||
return left.Equals(right);
|
ColumnSet2 right
|
||||||
}
|
)
|
||||||
|
{
|
||||||
}
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool operator ==(
|
||||||
|
ColumnSet2 left,
|
||||||
|
ColumnSet2 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+83
-83
@@ -1,83 +1,83 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ColumnSet3"
|
// file="ColumnSet3"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Mathematics.Internal;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Internal.Intrinsic
|
namespace StgSharp.Mathematics.Internal
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||||
internal struct ColumnSet3 : IEquatable<ColumnSet3>
|
internal struct ColumnSet3 : IEquatable<ColumnSet3>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||||
[FieldOffset(4 * sizeof(float))] internal float m01;
|
[FieldOffset(4 * sizeof(float))] internal float m01;
|
||||||
[FieldOffset(8 * sizeof(float))] internal float m02;
|
[FieldOffset(8 * sizeof(float))] internal float m02;
|
||||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||||
[FieldOffset(5 * sizeof(float))] internal float m11;
|
[FieldOffset(5 * sizeof(float))] internal float m11;
|
||||||
[FieldOffset(9 * sizeof(float))] internal float m12;
|
[FieldOffset(9 * sizeof(float))] internal float m12;
|
||||||
[FieldOffset(2 * sizeof(float))] internal float m20;
|
[FieldOffset(2 * sizeof(float))] internal float m20;
|
||||||
[FieldOffset(6 * sizeof(float))] internal float m21;
|
[FieldOffset(6 * sizeof(float))] internal float m21;
|
||||||
[FieldOffset(10 * sizeof(float))] internal float m22;
|
[FieldOffset(10 * sizeof(float))] internal float m22;
|
||||||
[FieldOffset(3 * sizeof(float))] internal float m30;
|
[FieldOffset(3 * sizeof(float))] internal float m30;
|
||||||
[FieldOffset(7 * sizeof(float))] internal float m31;
|
[FieldOffset(7 * sizeof(float))] internal float m31;
|
||||||
[FieldOffset(11 * sizeof(float))] internal float m32;
|
[FieldOffset(11 * sizeof(float))] internal float m32;
|
||||||
|
|
||||||
[FieldOffset(0)] internal Vector4 colum0;
|
[FieldOffset(0)] internal Vector4 colum0;
|
||||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||||
[FieldOffset(8 * sizeof(float))] internal Vector4 colum2;
|
[FieldOffset(8 * sizeof(float))] internal Vector4 colum2;
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
return (obj is ColumnSet3 mat) && Equals(mat);
|
return (obj is ColumnSet3 mat) && Equals(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Equals(ColumnSet3 other)
|
public bool Equals(ColumnSet3 other)
|
||||||
{
|
{
|
||||||
return colum0.Equals(other.colum0) && colum1.Equals(other.colum1) && colum2.Equals(other.colum2);
|
return colum0.Equals(other.colum0) && colum1.Equals(other.colum1) && colum2.Equals(other.colum2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator !=(ColumnSet3 left, ColumnSet3 right)
|
public static bool operator !=(ColumnSet3 left, ColumnSet3 right)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(ColumnSet3 left, ColumnSet3 right)
|
public static bool operator ==(ColumnSet3 left, ColumnSet3 right)
|
||||||
{
|
{
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+101
-101
@@ -1,101 +1,101 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ColumnSet4"
|
// file="ColumnSet4"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp;
|
using StgSharp;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Mathematics.Internal;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Internal.Intrinsic
|
namespace StgSharp.Mathematics.Internal
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
|
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
|
||||||
internal struct ColumnSet4 : IEquatable<ColumnSet4>
|
internal struct ColumnSet4 : IEquatable<ColumnSet4>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] internal Vector4 colum0;
|
[FieldOffset(0)] internal Vector4 colum0;
|
||||||
[FieldOffset(16)] internal Vector4 colum1;
|
[FieldOffset(16)] internal Vector4 colum1;
|
||||||
[FieldOffset(32)] internal Vector4 colum2;
|
[FieldOffset(32)] internal Vector4 colum2;
|
||||||
[FieldOffset(48)] internal Vector4 colum3;
|
[FieldOffset(48)] internal Vector4 colum3;
|
||||||
|
|
||||||
[FieldOffset(0)] public float m00;
|
[FieldOffset(0)] public float m00;
|
||||||
[FieldOffset(16)] public float m01;
|
[FieldOffset(16)] public float m01;
|
||||||
[FieldOffset(32)] public float m02;
|
[FieldOffset(32)] public float m02;
|
||||||
[FieldOffset(48)] public float m03;
|
[FieldOffset(48)] public float m03;
|
||||||
[FieldOffset(4)] public float m10;
|
[FieldOffset(4)] public float m10;
|
||||||
[FieldOffset(20)] public float m11;
|
[FieldOffset(20)] public float m11;
|
||||||
[FieldOffset(36)] public float m12;
|
[FieldOffset(36)] public float m12;
|
||||||
[FieldOffset(52)] public float m13;
|
[FieldOffset(52)] public float m13;
|
||||||
[FieldOffset(8)] public float m20;
|
[FieldOffset(8)] public float m20;
|
||||||
[FieldOffset(24)] public float m21;
|
[FieldOffset(24)] public float m21;
|
||||||
[FieldOffset(40)] public float m22;
|
[FieldOffset(40)] public float m22;
|
||||||
[FieldOffset(56)] public float m23;
|
[FieldOffset(56)] public float m23;
|
||||||
[FieldOffset(12)] public float m30;
|
[FieldOffset(12)] public float m30;
|
||||||
[FieldOffset(28)] public float m31;
|
[FieldOffset(28)] public float m31;
|
||||||
[FieldOffset(44)] public float m32;
|
[FieldOffset(44)] public float m32;
|
||||||
[FieldOffset(60)] public float m33;
|
[FieldOffset(60)] public float m33;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal ColumnSet4(Vector4 colum0, Vector4 colum1, Vector4 colum2, Vector4 colum3)
|
internal ColumnSet4(Vector4 colum0, Vector4 colum1, Vector4 colum2, Vector4 colum3)
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out this);
|
Unsafe.SkipInit(out this);
|
||||||
this.colum0 = colum0;
|
this.colum0 = colum0;
|
||||||
this.colum1 = colum1;
|
this.colum1 = colum1;
|
||||||
this.colum2 = colum2;
|
this.colum2 = colum2;
|
||||||
this.colum3 = colum3;
|
this.colum3 = colum3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
return (obj is ColumnSet4 mat) && Equals(mat);
|
return (obj is ColumnSet4 mat) && Equals(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Equals(ColumnSet4 other)
|
public bool Equals(ColumnSet4 other)
|
||||||
{
|
{
|
||||||
return colum0.Equals(other.colum0) &&
|
return colum0.Equals(other.colum0) &&
|
||||||
colum1.Equals(other.colum1) &&
|
colum1.Equals(other.colum1) &&
|
||||||
colum2.Equals(other.colum2) &&
|
colum2.Equals(other.colum2) &&
|
||||||
colum3.Equals(other.colum3);
|
colum3.Equals(other.colum3);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator !=(ColumnSet4 left, ColumnSet4 right)
|
public static bool operator !=(ColumnSet4 left, ColumnSet4 right)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(ColumnSet4 left, ColumnSet4 right)
|
public static bool operator ==(ColumnSet4 left, ColumnSet4 right)
|
||||||
{
|
{
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+122
-78
@@ -1,79 +1,123 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IntrinsicContext"
|
// file="IntrinsicContext"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using System.Numerics;
|
||||||
using System;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Numerics;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
namespace StgSharp.Mathematics.Internal
|
||||||
using System.Runtime.InteropServices.Marshalling;
|
{
|
||||||
|
[InlineArray(10)]
|
||||||
namespace StgSharp.Internal.Intrinsic
|
internal unsafe struct MatrixIntrinsic
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal unsafe struct MatrixIntrinsic
|
private nint handle; //f32_panel_mul
|
||||||
{
|
|
||||||
|
public readonly nint this[
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, long, void> buffer_add; //f32_buffer_add
|
MatrixIntrinsicHandle handle
|
||||||
public delegate* unmanaged[Cdecl]<void*, ScalarPacket*, long, void> buffer_fill; //f32_buffer_fill
|
]
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, ScalarPacket*, long, void> buffer_scalar_mul; //f32_buffer_s_m
|
{
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, long, void> buffer_sub; //f32_kernel_sub
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, void> buffer_transpose; //f32_kernel_transpose
|
get => this[(int)handle];
|
||||||
public delegate* unmanaged[Cdecl]<MatrixPanel*, MatrixKernel*, int, int, int, int, void> build_panel; //f32_build_panel
|
}
|
||||||
public delegate* unmanaged[Cdecl]<MatrixPanel*, void> clear_panel; //f32_clear_panel
|
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, void> kernel_fma; //f32_panel_fma
|
}
|
||||||
public delegate* unmanaged[Cdecl]<MatrixKernel*, MatrixKernel*, MatrixKernel*, M128*, void> kernel_tile_fma; //f32_panel_fma
|
|
||||||
public delegate* unmanaged[Cdecl]<void*, ulong, ulong, ulong, void> pivot; //f32_panel_mul
|
internal enum MatrixIntrinsicHandle : int
|
||||||
public delegate* unmanaged[Cdecl]<void*, void*, int, int, int, int, void> store_panel; //f32_store_panel
|
{
|
||||||
|
|
||||||
}
|
BufferAdd = 0,
|
||||||
|
BufferFill = 1,
|
||||||
[InlineArray(4)]
|
BufferScalarMul = 2,
|
||||||
internal unsafe struct MatrixIntrinsicArray
|
BufferSub = 3,
|
||||||
{
|
BufferTranspose = 4,
|
||||||
|
ClearPanel = 5,
|
||||||
private MatrixIntrinsic e0;
|
KerFma = 6,
|
||||||
|
TileFma = 7,
|
||||||
}
|
Pivot = 8,
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
}
|
||||||
internal unsafe struct IntrinsicContext
|
|
||||||
{
|
[StructLayout(LayoutKind.Explicit, Size = 4)]
|
||||||
|
public struct MatrixElementType
|
||||||
public delegate* unmanaged[Cdecl]<char*, int, int> city_hash_simplify; // city_hash_simplify
|
{
|
||||||
public delegate* unmanaged[Cdecl]<int, ulong> factorial_simd; // factorial_simd
|
|
||||||
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair; // index_pair
|
public const int IntrinsicCount = 0xa;
|
||||||
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> vec_f32_normalize_3; // f32_normalize_3
|
|
||||||
public MatrixIntrinsicArray mat; // mat[4] in native order
|
public static readonly MatrixElementType F32 = new(0x00010004);
|
||||||
|
public static readonly MatrixElementType F64 = new(0x00020008);
|
||||||
public IntrinsicContext()
|
public static readonly MatrixElementType I08 = new(0x00030001);
|
||||||
{
|
public static readonly MatrixElementType I16 = new(0x00040002);
|
||||||
Unsafe.SkipInit(out this);
|
public static readonly MatrixElementType I32 = new(0x00050004);
|
||||||
}
|
public static readonly MatrixElementType I64 = new(0x00060008);
|
||||||
|
public static readonly MatrixElementType U08 = new(0x00070001);
|
||||||
}
|
public static readonly MatrixElementType U16 = new(0x00080002);
|
||||||
|
public static readonly MatrixElementType U32 = new(0x00090004);
|
||||||
|
public static readonly MatrixElementType U64 = new(0x000a0008);
|
||||||
|
|
||||||
|
[FieldOffset(0)] internal readonly int Mask;
|
||||||
|
[FieldOffset(2)] public readonly ushort IntrinsicNode;
|
||||||
|
|
||||||
|
[FieldOffset(0)] public readonly ushort Size;
|
||||||
|
|
||||||
|
private MatrixElementType(
|
||||||
|
int mask
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Unsafe.SkipInit(out this);
|
||||||
|
Unsafe.SkipInit(out Size);
|
||||||
|
Unsafe.SkipInit(out IntrinsicNode);
|
||||||
|
this.Mask = mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[InlineArray(MatrixElementType.IntrinsicCount)]
|
||||||
|
internal unsafe struct MatrixIntrinsicArray
|
||||||
|
{
|
||||||
|
|
||||||
|
private MatrixIntrinsic e0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
internal unsafe struct IntrinsicContext
|
||||||
|
{
|
||||||
|
|
||||||
|
public delegate* unmanaged[Cdecl]<char*, int, int> city_hash_simplify; // city_hash_simplify
|
||||||
|
public delegate* unmanaged[Cdecl]<int, ulong> factorial_simd; // factorial_simd
|
||||||
|
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair; // index_pair
|
||||||
|
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> vec_f32_normalize_3; // f32_normalize_3
|
||||||
|
public MatrixIntrinsicArray mat; // mat[4] in native order
|
||||||
|
|
||||||
|
public IntrinsicContext()
|
||||||
|
{
|
||||||
|
Unsafe.SkipInit(out this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+51
-51
@@ -1,51 +1,51 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="SIMDID"
|
// file="SIMDID"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Internal.Intrinsic
|
namespace StgSharp.Mathematics.Internal
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
internal unsafe struct SIMDID
|
internal unsafe struct SIMDID
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)]public fixed byte MaskByte[16];
|
[FieldOffset(0)]public fixed byte MaskByte[16];
|
||||||
[FieldOffset(0)]public ulong Mask;
|
[FieldOffset(0)]public ulong Mask;
|
||||||
|
|
||||||
public SIMDID()
|
public SIMDID()
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out this);
|
Unsafe.SkipInit(out this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+78
-81
@@ -1,82 +1,79 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="intrinsicContextProvider.cs"
|
// file="intrinsicContextProvider"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// obtaining a copy of this software and associated documentation
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// files (the “Software”), to deal in the Software without restriction,
|
// in the Software without restriction, including without limitation the rights
|
||||||
// including without limitation the rights to use, copy, modify, merge,
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// and to permit persons to whom the Software is furnished to do so,
|
// furnished to do so, subject to the following conditions:
|
||||||
// subject to the following conditions:
|
//
|
||||||
//
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// The above copyright notice and
|
// copies or substantial portions of the Software.
|
||||||
// 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,
|
||||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
// SOFTWARE.
|
||||||
// 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 StgSharp.Mathematics.Internal;
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
using System;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System;
|
using System.Runtime.InteropServices;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
namespace StgSharp.Mathematics.Internal
|
||||||
using System.Runtime.InteropServices;
|
{
|
||||||
|
internal static unsafe partial class NativeIntrinsic
|
||||||
namespace StgSharp.Internal
|
{
|
||||||
{
|
|
||||||
internal static unsafe partial class NativeIntrinsic
|
private static readonly IntrinsicContext _intrinsicContext = new();
|
||||||
{
|
|
||||||
|
public static SIMDID IntrinsicMask { get; set; }
|
||||||
private static readonly IntrinsicContext _intrinsicContext = new();
|
|
||||||
|
internal static IntrinsicContext Context
|
||||||
public static SIMDID IntrinsicMask { get; set; }
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static IntrinsicContext Context
|
get => _intrinsicContext;
|
||||||
{
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => _intrinsicContext;
|
/*
|
||||||
}
|
internal static void InitIntrinsicContext()
|
||||||
|
{
|
||||||
/*
|
ulong statCode = 0;
|
||||||
internal static void InitIntrinsicContext()
|
|
||||||
{
|
fixed (IntrinsicContext* cPtr = &_intrinsicContext) {
|
||||||
ulong statCode = 0;
|
statCode = LoadIntrinsicFunction(cPtr);
|
||||||
|
}
|
||||||
fixed (IntrinsicContext* cPtr = &_intrinsicContext) {
|
SIMDID id = new()
|
||||||
statCode = LoadIntrinsicFunction(cPtr);
|
{
|
||||||
}
|
Mask = statCode
|
||||||
SIMDID id = new()
|
};
|
||||||
{
|
switch (id.MaskByte[1])
|
||||||
Mask = statCode
|
{
|
||||||
};
|
case 0:
|
||||||
switch (id.MaskByte[1])
|
Dialogue.PostError(new PlatformNotSupportedException("No SIMD instructions supported on current hardware platform"));
|
||||||
{
|
Environment.Exit(-1);
|
||||||
case 0:
|
break;
|
||||||
Dialogue.PostError(new PlatformNotSupportedException("No SIMD instructions supported on current hardware platform"));
|
default:
|
||||||
Environment.Exit(-1);
|
break;
|
||||||
break;
|
}
|
||||||
default:
|
IntrinsicMask = id;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
IntrinsicMask = id;
|
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||||
}
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
|
private static partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id);
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
/**/
|
||||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
}
|
||||||
private static partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id);
|
|
||||||
/**/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+263
-262
@@ -1,262 +1,263 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix44"
|
// file="Matrix44"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Internal;
|
||||||
using System;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System.Collections;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections;
|
||||||
using System.Numerics;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
namespace StgSharp.Mathematics.Graphic
|
|
||||||
{
|
namespace StgSharp.Mathematics.Graphics
|
||||||
[StructLayout(LayoutKind.Explicit, Size = (16 * sizeof(float)), Pack = 16)]
|
{
|
||||||
public unsafe struct Matrix44 : IEquatable<Matrix44>
|
[StructLayout(LayoutKind.Explicit, Size = (16 * sizeof(float)), Pack = 16)]
|
||||||
{
|
public unsafe struct Matrix44 : IEquatable<Matrix44>
|
||||||
|
{
|
||||||
[FieldOffset(0 * sizeof(float))] internal Column column;
|
|
||||||
|
[FieldOffset(0 * sizeof(float))] internal Column column;
|
||||||
[FieldOffset(0)] internal ColumnSet4 mat;
|
|
||||||
[FieldOffset(0)] internal MatrixKernel<float> kernel;
|
[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;
|
Unsafe.SkipInit(out this);
|
||||||
}
|
this.mat = mat;
|
||||||
|
}
|
||||||
internal Matrix44(
|
|
||||||
Vector4 vec0,
|
internal Matrix44(
|
||||||
Vector4 vec1,
|
Vector4 vec0,
|
||||||
Vector4 vec2,
|
Vector4 vec1,
|
||||||
Vector4 vec3
|
Vector4 vec2,
|
||||||
)
|
Vector4 vec3
|
||||||
{
|
)
|
||||||
Unsafe.SkipInit(out this);
|
{
|
||||||
mat.colum0 = vec0;
|
Unsafe.SkipInit(out this);
|
||||||
mat.colum1 = vec1;
|
mat.colum0 = vec0;
|
||||||
mat.colum2 = vec2;
|
mat.colum1 = vec1;
|
||||||
mat.colum3 = vec3;
|
mat.colum2 = vec2;
|
||||||
}
|
mat.colum3 = vec3;
|
||||||
|
}
|
||||||
public Matrix44()
|
|
||||||
{
|
public Matrix44()
|
||||||
Unsafe.SkipInit(out this);
|
{
|
||||||
}
|
Unsafe.SkipInit(out this);
|
||||||
|
}
|
||||||
public unsafe Matrix44(
|
|
||||||
float a00,
|
public unsafe Matrix44(
|
||||||
float a01,
|
float a00,
|
||||||
float a02,
|
float a01,
|
||||||
float a03,
|
float a02,
|
||||||
float a10,
|
float a03,
|
||||||
float a11,
|
float a10,
|
||||||
float a12,
|
float a11,
|
||||||
float a13,
|
float a12,
|
||||||
float a20,
|
float a13,
|
||||||
float a21,
|
float a20,
|
||||||
float a22,
|
float a21,
|
||||||
float a23,
|
float a22,
|
||||||
float a30,
|
float a23,
|
||||||
float a31,
|
float a30,
|
||||||
float a32,
|
float a31,
|
||||||
float a33
|
float a32,
|
||||||
)
|
float a33
|
||||||
{
|
)
|
||||||
Unsafe.SkipInit(out this);
|
{
|
||||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
Unsafe.SkipInit(out this);
|
||||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||||
mat.colum2 = new Vector4(a02, a12, a22, a32);
|
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||||
mat.colum3 = new Vector4(a03, a13, a23, a33);
|
mat.colum2 = new Vector4(a02, a12, a22, a32);
|
||||||
}
|
mat.colum3 = new Vector4(a03, a13, a23, a33);
|
||||||
|
}
|
||||||
public unsafe float this[
|
|
||||||
int rowNum,
|
public unsafe float this[
|
||||||
int columNum
|
int rowNum,
|
||||||
]
|
int columNum
|
||||||
{
|
]
|
||||||
get
|
{
|
||||||
{
|
get
|
||||||
#if DEBUG
|
{
|
||||||
if (rowNum is > 3 or < 0)
|
#if DEBUG
|
||||||
{
|
if (rowNum is > 3 or < 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
{
|
||||||
}
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
if (columNum is > 3 or < 0) {
|
}
|
||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
if (columNum is > 3 or < 0) {
|
||||||
}
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
#endif
|
}
|
||||||
return kernel[rowNum + 4 * columNum];
|
#endif
|
||||||
}
|
return kernel[rowNum + 4 * columNum];
|
||||||
set
|
}
|
||||||
{
|
set
|
||||||
#if DEBUG
|
{
|
||||||
if (rowNum is > 3 or < 0)
|
#if DEBUG
|
||||||
{
|
if (rowNum is > 3 or < 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
{
|
||||||
}
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
if (columNum is > 3 or < 0) {
|
}
|
||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
if (columNum is > 3 or < 0) {
|
||||||
}
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
#endif
|
}
|
||||||
kernel[rowNum + 4 * columNum] = value;
|
#endif
|
||||||
}
|
kernel[rowNum + 4 * columNum] = value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public Matrix44 Transpose
|
|
||||||
{
|
public Matrix44 Transpose
|
||||||
get
|
{
|
||||||
{
|
get
|
||||||
Matrix44 transpose = new();
|
{
|
||||||
InternalTranspose(ref transpose);
|
Matrix44 transpose = new();
|
||||||
return transpose;
|
InternalTranspose(ref 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 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()
|
|
||||||
{
|
public ReadOnlySpan<float> AsSpan()
|
||||||
return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<ColumnSet4, float>(ref mat), 16);
|
{
|
||||||
}
|
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);
|
{
|
||||||
}
|
return obj is Matrix44 x && Equals(x);
|
||||||
|
}
|
||||||
public bool Equals(
|
|
||||||
Matrix44 other
|
public bool Equals(
|
||||||
)
|
Matrix44 other
|
||||||
{
|
)
|
||||||
return mat.Equals(other.mat);
|
{
|
||||||
}
|
return mat.Equals(other.mat);
|
||||||
|
}
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
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(
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
ref Matrix44 transpose
|
internal unsafe void InternalTranspose(
|
||||||
)
|
ref Matrix44 transpose
|
||||||
{
|
)
|
||||||
const int f32 = 0;
|
{
|
||||||
fixed (MatrixKernel<float>* source = &this.kernel, target = &transpose.kernel) {
|
const int f32 = 0;
|
||||||
NativeIntrinsic.Context.mat[f32].buffer_transpose(source, target);
|
fixed (MatrixKernel<float>* source = &this.kernel, target = &transpose.kernel) {
|
||||||
}
|
NativeIntrinsic.Context.mat[f32].buffer_transpose(source, target);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe Matrix44 operator -(
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
Matrix44 left,
|
public static unsafe Matrix44 operator -(
|
||||||
Matrix44 right
|
Matrix44 left,
|
||||||
)
|
Matrix44 right
|
||||||
{
|
)
|
||||||
Matrix44 ret = new();
|
{
|
||||||
const int f32 = 0;
|
Matrix44 ret = new();
|
||||||
NativeIntrinsic.Context.mat[f32].buffer_sub(&left, &right, &ret, 1);
|
const int f32 = 0;
|
||||||
return ret;
|
NativeIntrinsic.Context.mat[f32].buffer_sub(&left, &right, &ret, 1);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
public static bool operator !=(
|
|
||||||
Matrix44 left,
|
public static bool operator !=(
|
||||||
Matrix44 right
|
Matrix44 left,
|
||||||
)
|
Matrix44 right
|
||||||
{
|
)
|
||||||
return !(left == right);
|
{
|
||||||
}
|
return !(left == right);
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe Matrix44 operator *(
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
Matrix44 mat,
|
public static unsafe Matrix44 operator *(
|
||||||
float value
|
Matrix44 mat,
|
||||||
)
|
float value
|
||||||
{
|
)
|
||||||
return new Matrix44(mat.mat.colum0 * value, mat.mat.colum1 * value,
|
{
|
||||||
mat.mat.colum2 * value, mat.mat.colum3 * value);
|
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 *(
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
Matrix44 left,
|
public static Matrix44 operator *(
|
||||||
Matrix44 right
|
Matrix44 left,
|
||||||
)
|
Matrix44 right
|
||||||
{
|
)
|
||||||
Matrix44 ret = new();
|
{
|
||||||
int f32 = (int)MatrixElementType.F32;
|
Matrix44 ret = new();
|
||||||
NativeIntrinsic.Context.mat[f32].kernel_fma(&left, &right, &ret);
|
int f32 = (int)MatrixElementType.F32;
|
||||||
return ret;
|
NativeIntrinsic.Context.mat[f32].kernel_fma(&left, &right, &ret);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe Matrix44 operator +(
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
Matrix44 left,
|
public static unsafe Matrix44 operator +(
|
||||||
Matrix44 right
|
Matrix44 left,
|
||||||
)
|
Matrix44 right
|
||||||
{
|
)
|
||||||
Matrix44 ret = new();
|
{
|
||||||
const int f32 = 0;
|
Matrix44 ret = new();
|
||||||
NativeIntrinsic.Context.mat[f32].buffer_add(&left, &right, &ret, 1);
|
const int f32 = 0;
|
||||||
return ret;
|
NativeIntrinsic.Context.mat[f32].buffer_add(&left, &right, &ret, 1);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
public static bool operator ==(
|
|
||||||
Matrix44 left,
|
public static bool operator ==(
|
||||||
Matrix44 right
|
Matrix44 left,
|
||||||
)
|
Matrix44 right
|
||||||
{
|
)
|
||||||
return left.Equals(right);
|
{
|
||||||
}
|
return left.Equals(right);
|
||||||
|
}
|
||||||
[InlineArray(4)]
|
|
||||||
internal struct Column
|
[InlineArray(4)]
|
||||||
{
|
internal struct Column
|
||||||
|
{
|
||||||
private Vec4 value;
|
|
||||||
|
private Vec4 value;
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+162
-162
@@ -1,162 +1,162 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vec2"
|
// file="Vec2"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A two dimension vector defined by two elements. Vec2 in World are default used as colum
|
/// A two dimension vector defined by two elements. Vec2 in World are default used as colum
|
||||||
/// vector.
|
/// vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||||
public struct Vec2 : IUnmanagedVector<Vec2>
|
public struct Vec2 : IUnmanagedVector<Vec2>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] internal unsafe fixed float num[2];
|
[FieldOffset(0)] internal unsafe fixed float num[2];
|
||||||
|
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
internal M128 reg;
|
internal M128 reg;
|
||||||
|
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
internal Vector2 v;
|
internal Vector2 v;
|
||||||
|
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public float X;
|
public float X;
|
||||||
[FieldOffset(4)]
|
[FieldOffset(4)]
|
||||||
public float Y;
|
public float Y;
|
||||||
|
|
||||||
internal Vec2(Vector2 vec)
|
internal Vec2(Vector2 vec)
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out reg);
|
Unsafe.SkipInit(out reg);
|
||||||
Unsafe.SkipInit(out X);
|
Unsafe.SkipInit(out X);
|
||||||
Unsafe.SkipInit(out Y);
|
Unsafe.SkipInit(out Y);
|
||||||
v = vec;
|
v = vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Vec2(M128 vec)
|
internal Vec2(M128 vec)
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out reg);
|
Unsafe.SkipInit(out reg);
|
||||||
Unsafe.SkipInit(out X);
|
Unsafe.SkipInit(out X);
|
||||||
Unsafe.SkipInit(out Y);
|
Unsafe.SkipInit(out Y);
|
||||||
reg = vec;
|
reg = vec;
|
||||||
reg.Member<ulong>(1) = 0;
|
reg.Member<ulong>(1) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec2(float x, float y)
|
public Vec2(float x, float y)
|
||||||
{
|
{
|
||||||
v = new Vector2(x, y);
|
v = new Vector2(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec2 Unit => new Vec2(1, 1);
|
public static Vec2 Unit => new Vec2(1, 1);
|
||||||
|
|
||||||
public static Vec2 Zero => new Vec2(0, 0);
|
public static Vec2 Zero => new Vec2(0, 0);
|
||||||
|
|
||||||
public static Vec2 One
|
public static Vec2 One
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => new Vec2(1, 1);
|
get => new Vec2(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec2 XY
|
public Vec2 XY
|
||||||
{
|
{
|
||||||
readonly get => this;
|
readonly get => this;
|
||||||
set => this = value;
|
set => this = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 XYZ
|
public Vec3 XYZ
|
||||||
{
|
{
|
||||||
readonly get => new(reg);
|
readonly get => new(reg);
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
reg = value.reg;
|
reg = value.reg;
|
||||||
reg.Member<ulong>(1) = 0;
|
reg.Member<ulong>(1) = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public float Cross(Vec2 right)
|
public float Cross(Vec2 right)
|
||||||
{
|
{
|
||||||
return X * right.Y - Y * right.X;
|
return X * right.Y - Y * right.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public float Dot(Vec2 vec)
|
public float Dot(Vec2 vec)
|
||||||
{
|
{
|
||||||
return Vector2.Dot(v, vec.v);
|
return Vector2.Dot(v, vec.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec2 operator -(Vec2 left, Vec2 right)
|
public static Vec2 operator -(Vec2 left, Vec2 right)
|
||||||
{
|
{
|
||||||
return new Vec2(left.v - right.v);
|
return new Vec2(left.v - right.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(Vec2 left, Vec2 right)
|
public static bool operator !=(Vec2 left, Vec2 right)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec2 operator *(Vec2 vec, float value)
|
public static Vec2 operator *(Vec2 vec, float value)
|
||||||
{
|
{
|
||||||
return new Vec2(vec.v * value);
|
return new Vec2(vec.v * value);
|
||||||
}
|
}
|
||||||
public static Vec2 operator *(float value, Vec2 vec)
|
public static Vec2 operator *(float value, Vec2 vec)
|
||||||
{
|
{
|
||||||
return new Vec2(vec.v * value);
|
return new Vec2(vec.v * value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec2 operator /(Vec2 vec, float value)
|
public static Vec2 operator /(Vec2 vec, float value)
|
||||||
{
|
{
|
||||||
return new Vec2(vec.v / value);
|
return new Vec2(vec.v / value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec2 operator +(Vec2 left, Vec2 right)
|
public static Vec2 operator +(Vec2 left, Vec2 right)
|
||||||
{
|
{
|
||||||
return new Vec2(left.v + right.v);
|
return new Vec2(left.v + right.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(Vec2 left, Vec2 right)
|
public static bool operator ==(Vec2 left, Vec2 right)
|
||||||
{
|
{
|
||||||
return left.v == right.v;
|
return left.v == right.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator Vec2((float, float) tuple)
|
public static implicit operator Vec2((float, float) tuple)
|
||||||
{
|
{
|
||||||
return new Vec2(tuple.Item1, tuple.Item2);
|
return new Vec2(tuple.Item1, tuple.Item2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+288
-236
@@ -1,236 +1,288 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vec3"
|
// file="Vec3"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
[CollectionBuilder(typeof(Vec3), nameof(FromSpan))]
|
[CollectionBuilder(typeof(Vec3), nameof(FromSpan))]
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||||
public struct Vec3 : IEquatable<Vec3>, IUnmanagedVector<Vec3>, IEnumerable<float>
|
public struct Vec3 : IEquatable<Vec3>, IUnmanagedVector<Vec3>, IEnumerable<float>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] internal unsafe fixed float num[3];
|
[FieldOffset(0)] internal unsafe fixed float num[3];
|
||||||
[FieldOffset(0)] internal M128 reg;
|
[FieldOffset(0)] internal M128 reg;
|
||||||
|
|
||||||
[FieldOffset(0)] internal Vector3 v;
|
[FieldOffset(0)] internal Vector3 v;
|
||||||
|
|
||||||
[FieldOffset(0)] public float X;
|
[FieldOffset(0)] public float X;
|
||||||
[FieldOffset(4)] public float Y;
|
[FieldOffset(4)] public float Y;
|
||||||
[FieldOffset(8)] public float Z;
|
[FieldOffset(8)] public float Z;
|
||||||
|
|
||||||
internal Vec3(M128 vector)
|
internal Vec3(
|
||||||
{
|
M128 vector
|
||||||
Unsafe.SkipInit(out this);
|
)
|
||||||
reg = vector;
|
{
|
||||||
reg.Member<uint>(3) = 0;
|
Unsafe.SkipInit(out this);
|
||||||
}
|
reg = vector;
|
||||||
|
reg.Member<uint>(3) = 0;
|
||||||
internal Vec3(Vector3 vector)
|
}
|
||||||
{
|
|
||||||
v = vector;
|
internal Vec3(
|
||||||
}
|
Vector3 vector
|
||||||
|
)
|
||||||
public Vec3()
|
{
|
||||||
{
|
v = vector;
|
||||||
Unsafe.SkipInit(out this);
|
}
|
||||||
}
|
|
||||||
|
public Vec3()
|
||||||
public Vec3(Vec2 xy, float z)
|
{
|
||||||
{
|
Unsafe.SkipInit(out this);
|
||||||
Unsafe.SkipInit(out this);
|
}
|
||||||
reg = xy.reg;
|
|
||||||
Z = z;
|
public Vec3(
|
||||||
}
|
Vec2 xy,
|
||||||
|
float z
|
||||||
public Vec3(float x, float y, float z)
|
)
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out this);
|
Unsafe.SkipInit(out this);
|
||||||
v = new Vector3(x, y, z);
|
reg = xy.reg;
|
||||||
}
|
Z = z;
|
||||||
|
}
|
||||||
public unsafe Vec2 XY
|
|
||||||
{
|
public Vec3(
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
float x,
|
||||||
readonly get => new(reg);
|
float y,
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
float z
|
||||||
set => Unsafe.As<Vector3, Vector2>(ref v) = value.v;
|
)
|
||||||
}
|
{
|
||||||
|
Unsafe.SkipInit(out this);
|
||||||
public Vec3 XYZ
|
v = new Vector3(x, y, z);
|
||||||
{
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
readonly get => new(v);
|
public unsafe Vec2 XY
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
{
|
||||||
set => this = value;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
readonly get => new(reg);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec3 Zero => new(0, 0, 0);
|
set => Unsafe.As<Vector3, Vector2>(ref v) = value.v;
|
||||||
|
}
|
||||||
public static Vec3 One => new(1, 1, 1);
|
|
||||||
|
public Vec3 XYZ
|
||||||
public static Vec3 UnitX => new(1, 0, 0);
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec3 UnitY => new(0, 1, 0);
|
readonly get => new(v);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec3 UnitZ => new(0, 0, 1);
|
set => this = value;
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static Vec3 Cross(Vec3 left, Vec3 right)
|
public static Vec3 Zero => new(0, 0, 0);
|
||||||
{
|
|
||||||
return Linear.Cross(left, right);
|
public static Vec3 One => new(1, 1, 1);
|
||||||
}
|
|
||||||
|
public static Vec3 UnitX => new(1, 0, 0);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public readonly float Dot(Vec3 right)
|
public static Vec3 UnitY => new(0, 1, 0);
|
||||||
{
|
|
||||||
return Vector3.Dot(v, right.v);
|
public static Vec3 UnitZ => new(0, 0, 1);
|
||||||
}
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public readonly bool Equals(Vec3 other)
|
public static Vec3 Cross(
|
||||||
{
|
Vec3 left,
|
||||||
return reg == other.reg;
|
Vec3 right
|
||||||
}
|
)
|
||||||
|
{
|
||||||
public override readonly bool Equals(object obj)
|
return Linear.Cross(left, right);
|
||||||
{
|
}
|
||||||
return obj is not null && obj is Vec3 vec && this == vec;
|
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public readonly float Dot(
|
||||||
public static Vec3 FromSpan(ReadOnlySpan<float> span)
|
Vec3 right
|
||||||
{
|
)
|
||||||
Vec3 v = new();
|
{
|
||||||
span.CopyTo(MemoryMarshal.CreateSpan(ref v.X, 3));
|
return Vector3.Dot(v, right.v);
|
||||||
return v;
|
}
|
||||||
}
|
|
||||||
|
public readonly bool Equals(
|
||||||
public unsafe IEnumerator<float> GetEnumerator()
|
Vec3 other
|
||||||
{
|
)
|
||||||
for (int i = 0; i < 3; i++) {
|
{
|
||||||
yield return reg.Member<float>(i);
|
return reg == other.reg;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public override readonly bool Equals(
|
||||||
public override unsafe int GetHashCode()
|
object obj
|
||||||
{
|
)
|
||||||
fixed (float* add = &X) {
|
{
|
||||||
return HashCode.Combine(X, Y, Z, (ulong)add);
|
return obj is not null && obj is Vec3 vec && this == vec;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static Vec3 FromSpan(
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
ReadOnlySpan<float> span
|
||||||
public readonly float GetMaxValue()
|
)
|
||||||
{
|
{
|
||||||
float ret = X;
|
Vec3 v = new();
|
||||||
ret = ret > Y ? ret : Y;
|
span.CopyTo(MemoryMarshal.CreateSpan(ref v.X, 3));
|
||||||
ret = ret > Z ? ret : Z;
|
return v;
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
|
public unsafe IEnumerator<float> GetEnumerator()
|
||||||
public static bool IsParallel(Vec3 left, Vec3 right)
|
{
|
||||||
{
|
for (int i = 0; i < 3; i++) {
|
||||||
return Cross(left, right) == Zero;
|
yield return reg.Member<float>(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public override readonly string ToString()
|
|
||||||
{
|
public override unsafe int GetHashCode()
|
||||||
return $"[{X},{Y},{Z}]";
|
{
|
||||||
}
|
fixed (float* add = &X) {
|
||||||
|
return HashCode.Combine(X, Y, Z, (ulong)add);
|
||||||
public readonly string ToString(string sample)
|
}
|
||||||
{
|
}
|
||||||
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
|
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public readonly float GetMaxValue()
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
{
|
||||||
public static Vec3 operator -(Vec3 vec)
|
float ret = X;
|
||||||
{
|
ret = ret > Y ? ret : Y;
|
||||||
return new Vec3(-vec.v);
|
ret = ret > Z ? ret : Z;
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static Vec3 operator -(Vec3 left, Vec3 right)
|
public static bool IsParallel(
|
||||||
{
|
Vec3 left,
|
||||||
return new Vec3(left.v - right.v);
|
Vec3 right
|
||||||
}
|
)
|
||||||
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
return Cross(left, right) == Zero;
|
||||||
public static bool operator !=(Vec3 left, Vec3 right)
|
}
|
||||||
{
|
|
||||||
return left.v != right.v;
|
public override readonly string ToString()
|
||||||
}
|
{
|
||||||
|
return $"[{X},{Y},{Z}]";
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
}
|
||||||
public static Vec3 operator *(Vec3 vec, float value)
|
|
||||||
{
|
public readonly string ToString(
|
||||||
return new Vec3(vec.v * value);
|
string sample
|
||||||
}
|
)
|
||||||
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
|
||||||
public static float operator *(Vec3 left, Vec3 right)
|
}
|
||||||
{
|
|
||||||
return Vector3.Dot(left.v, right.v);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
public static Vec3 operator -(
|
||||||
|
Vec3 vec
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
)
|
||||||
public static Vec3 operator /(Vec3 vec, float value)
|
{
|
||||||
{
|
return new Vec3(-vec.v);
|
||||||
return new Vec3(vec.v / value);
|
}
|
||||||
}
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
public static Vec3 operator -(
|
||||||
public static Vec3 operator +(Vec3 left, Vec3 right)
|
Vec3 left,
|
||||||
{
|
Vec3 right
|
||||||
return new Vec3(left.v + right.v);
|
)
|
||||||
}
|
{
|
||||||
|
return new Vec3(left.v - right.v);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
}
|
||||||
public static bool operator ==(Vec3 left, Vec3 right)
|
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
return left.v == right.v;
|
public static bool operator !=(
|
||||||
}
|
Vec3 left,
|
||||||
|
Vec3 right
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
)
|
||||||
public static unsafe implicit operator Vec3((float, float, float) tuple)
|
{
|
||||||
{
|
return left.v != right.v;
|
||||||
return Unsafe.As<(float,float,float), Vec3>(ref tuple);
|
}
|
||||||
}
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
public static Vec3 operator *(
|
||||||
{
|
Vec3 vec,
|
||||||
return GetEnumerator();
|
float value
|
||||||
}
|
)
|
||||||
|
{
|
||||||
}
|
return new Vec3(vec.v * value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static float operator *(
|
||||||
|
Vec3 left,
|
||||||
|
Vec3 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return Vector3.Dot(left.v, right.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static Vec3 operator /(
|
||||||
|
Vec3 vec,
|
||||||
|
float value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return new Vec3(vec.v / value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static Vec3 operator +(
|
||||||
|
Vec3 left,
|
||||||
|
Vec3 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return new Vec3(left.v + right.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool operator ==(
|
||||||
|
Vec3 left,
|
||||||
|
Vec3 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return left.v == right.v;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static unsafe implicit operator Vec3(
|
||||||
|
(float, float, float) tuple
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return Unsafe.As<(float,float,float), Vec3>(ref tuple);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+250
-211
@@ -1,212 +1,251 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vec4"
|
// file="Vec4"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Mathematics.Internal;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System;
|
using System;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
[CollectionBuilder(builderType:typeof(Vec4), methodName: nameof(Vec4.FromSpan))]
|
[CollectionBuilder(builderType:typeof(Vec4), methodName: nameof(Vec4.FromSpan))]
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||||
public unsafe struct Vec4 : IEquatable<Vec4>, IUnmanagedVector<Vec4>
|
public unsafe struct Vec4 : IEquatable<Vec4>, IUnmanagedVector<Vec4>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] internal unsafe fixed float num[4];
|
[FieldOffset(0)] internal unsafe fixed float num[4];
|
||||||
|
|
||||||
[FieldOffset(0)] internal M128 reg;
|
[FieldOffset(0)] internal M128 reg;
|
||||||
|
|
||||||
[FieldOffset(0)] internal Vector4 vec;
|
[FieldOffset(0)] internal Vector4 vec;
|
||||||
[FieldOffset(12)] public float W;
|
[FieldOffset(12)] public float W;
|
||||||
|
|
||||||
[FieldOffset(0)] public float X;
|
[FieldOffset(0)] public float X;
|
||||||
[FieldOffset(4)] public float Y;
|
[FieldOffset(4)] public float Y;
|
||||||
[FieldOffset(8)] public float Z;
|
[FieldOffset(8)] public float Z;
|
||||||
|
|
||||||
internal Vec4(Vector4 v)
|
internal Vec4(
|
||||||
{
|
Vector4 v
|
||||||
Unsafe.SkipInit(out X);
|
)
|
||||||
Unsafe.SkipInit(out Y);
|
{
|
||||||
Unsafe.SkipInit(out Z);
|
Unsafe.SkipInit(out X);
|
||||||
Unsafe.SkipInit(out W);
|
Unsafe.SkipInit(out Y);
|
||||||
Unsafe.SkipInit(out reg);
|
Unsafe.SkipInit(out Z);
|
||||||
|
Unsafe.SkipInit(out W);
|
||||||
vec = v;
|
Unsafe.SkipInit(out reg);
|
||||||
}
|
|
||||||
|
vec = v;
|
||||||
internal Vec4(M128 v)
|
}
|
||||||
{
|
|
||||||
Unsafe.SkipInit(out X);
|
internal Vec4(
|
||||||
Unsafe.SkipInit(out Y);
|
M128 v
|
||||||
Unsafe.SkipInit(out Z);
|
)
|
||||||
Unsafe.SkipInit(out W);
|
{
|
||||||
Unsafe.SkipInit(out vec);
|
Unsafe.SkipInit(out X);
|
||||||
|
Unsafe.SkipInit(out Y);
|
||||||
reg = v;
|
Unsafe.SkipInit(out Z);
|
||||||
}
|
Unsafe.SkipInit(out W);
|
||||||
|
Unsafe.SkipInit(out vec);
|
||||||
public Vec4(Vec3 v3, float w)
|
|
||||||
{
|
reg = v;
|
||||||
Unsafe.SkipInit(out X);
|
}
|
||||||
Unsafe.SkipInit(out Y);
|
|
||||||
Unsafe.SkipInit(out Z);
|
public Vec4(
|
||||||
Unsafe.SkipInit(out W);
|
Vec3 v3,
|
||||||
reg = v3.reg;
|
float w
|
||||||
W = w;
|
)
|
||||||
}
|
{
|
||||||
|
Unsafe.SkipInit(out X);
|
||||||
public Vec4(float x, float y, float z, float w)
|
Unsafe.SkipInit(out Y);
|
||||||
{
|
Unsafe.SkipInit(out Z);
|
||||||
vec = new Vector4(x, y, z, w);
|
Unsafe.SkipInit(out W);
|
||||||
}
|
reg = v3.reg;
|
||||||
|
W = w;
|
||||||
public unsafe Vec2 XY
|
}
|
||||||
{
|
|
||||||
get => new Vec2(reg);
|
public Vec4(
|
||||||
set
|
float x,
|
||||||
{
|
float y,
|
||||||
X = value.X;
|
float z,
|
||||||
Y = value.Y;
|
float w
|
||||||
}
|
)
|
||||||
}
|
{
|
||||||
|
vec = new Vector4(x, y, z, w);
|
||||||
public unsafe Vec3 XYZ
|
}
|
||||||
{
|
|
||||||
get => new Vec3(reg);
|
public unsafe Vec2 XY
|
||||||
set
|
{
|
||||||
{
|
get => new Vec2(reg);
|
||||||
float w = W;
|
set
|
||||||
reg = value.reg;
|
{
|
||||||
W = w;
|
X = value.X;
|
||||||
}
|
Y = value.Y;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static Vec4 One
|
|
||||||
{
|
public unsafe Vec3 XYZ
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
{
|
||||||
get => new Vec4(1, 1, 1, 1);
|
get => new Vec3(reg);
|
||||||
}
|
set
|
||||||
|
{
|
||||||
public static Vec4 Zero
|
float w = W;
|
||||||
{
|
reg = value.reg;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
W = w;
|
||||||
get => new Vec4(0, 0, 0, 0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
public static Vec4 One
|
||||||
public static Vec4 Add(Vec4 left, Vec4 right)
|
{
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
return left + right;
|
get => new Vec4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlySpan<float> AsSpan()
|
public static Vec4 Zero
|
||||||
{
|
{
|
||||||
return MemoryMarshal.CreateReadOnlySpan(ref reg.Member<float>(0), 4);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
get => new Vec4(0, 0, 0, 0);
|
||||||
|
}
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
return obj is Vec4 v && v == this;
|
public static Vec4 Add(
|
||||||
}
|
Vec4 left,
|
||||||
|
Vec4 right
|
||||||
public static Vec4 FromSpan(ReadOnlySpan<float> span)
|
)
|
||||||
{
|
{
|
||||||
if (span.Length < 4) {
|
return left + right;
|
||||||
throw new ArgumentException("Span length must be at least 4.", nameof(span));
|
}
|
||||||
}
|
|
||||||
|
public ReadOnlySpan<float> AsSpan()
|
||||||
// Read 4 floats as a Vector4 in one operation without per-element copy.
|
{
|
||||||
Vector4 v = MemoryMarshal.Read<Vector4>(MemoryMarshal.AsBytes(span));
|
return MemoryMarshal.CreateReadOnlySpan(ref reg.Member<float>(0), 4);
|
||||||
return new Vec4(v);
|
}
|
||||||
}
|
|
||||||
|
public override bool Equals(
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
object obj
|
||||||
public ReadOnlySpan<float>.Enumerator GetEnumerator()
|
)
|
||||||
{
|
{
|
||||||
return AsSpan().GetEnumerator();
|
return obj is Vec4 v && v == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public static Vec4 FromSpan(
|
||||||
{
|
ReadOnlySpan<float> span
|
||||||
return vec.GetHashCode();
|
)
|
||||||
}
|
{
|
||||||
|
if (span.Length < 4) {
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
throw new ArgumentException("Span length must be at least 4.", nameof(span));
|
||||||
public static Vec4 Subtract(Vec4 left, Vec4 right)
|
}
|
||||||
{
|
|
||||||
return left - right;
|
// Read 4 floats as a Vector4 in one operation without per-element copy.
|
||||||
}
|
Vector4 v = MemoryMarshal.Read<Vector4>(MemoryMarshal.AsBytes(span));
|
||||||
|
return new Vec4(v);
|
||||||
public override string ToString()
|
}
|
||||||
{
|
|
||||||
return vec.ToString();
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
public ReadOnlySpan<float>.Enumerator GetEnumerator()
|
||||||
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
return AsSpan().GetEnumerator();
|
||||||
public static Vec4 operator -(Vec4 left, Vec4 right)
|
}
|
||||||
{
|
|
||||||
return new Vec4(left.vec - right.vec);
|
public override int GetHashCode()
|
||||||
}
|
{
|
||||||
|
return vec.GetHashCode();
|
||||||
public static bool operator !=(Vec4 left, Vec4 right)
|
}
|
||||||
{
|
|
||||||
return !(left == right);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
public static Vec4 Subtract(
|
||||||
|
Vec4 left,
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
Vec4 right
|
||||||
public static Vec4 operator *(Matrix44 mat, Vec4 vec)
|
)
|
||||||
{
|
{
|
||||||
Matrix44 transpose = mat.Transpose;
|
return left - right;
|
||||||
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec),
|
}
|
||||||
Vector4.Dot(transpose.mat.colum1, vec.vec),
|
|
||||||
Vector4.Dot(transpose.mat.colum2, vec.vec),
|
public override string ToString()
|
||||||
Vector4.Dot(transpose.mat.colum3, vec.vec));
|
{
|
||||||
}
|
return vec.ToString();
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static Vec4 operator +(Vec4 left, Vec4 right)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
{
|
public static Vec4 operator -(
|
||||||
return new Vec4(left.vec + right.vec);
|
Vec4 left,
|
||||||
}
|
Vec4 right
|
||||||
|
)
|
||||||
public static bool operator ==(Vec4 left, Vec4 right)
|
{
|
||||||
{
|
return new Vec4(left.vec - right.vec);
|
||||||
return left.vec == right.vec;
|
}
|
||||||
}
|
|
||||||
|
public static bool operator !=(
|
||||||
bool IEquatable<Vec4>.Equals(Vec4 other)
|
Vec4 left,
|
||||||
{
|
Vec4 right
|
||||||
return vec == other.vec;
|
)
|
||||||
}
|
{
|
||||||
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static Vec4 operator *(
|
||||||
|
Matrix44 mat,
|
||||||
|
Vec4 vec
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Matrix44 transpose = mat.Transpose;
|
||||||
|
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec),
|
||||||
|
Vector4.Dot(transpose.mat.colum1, vec.vec),
|
||||||
|
Vector4.Dot(transpose.mat.colum2, vec.vec),
|
||||||
|
Vector4.Dot(transpose.mat.colum3, vec.vec));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static Vec4 operator +(
|
||||||
|
Vec4 left,
|
||||||
|
Vec4 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return new Vec4(left.vec + right.vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(
|
||||||
|
Vec4 left,
|
||||||
|
Vec4 right
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return left.vec == right.vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IEquatable<Vec4>.Equals(
|
||||||
|
Vec4 other
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return vec == other.vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+49
-49
@@ -1,49 +1,49 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vector.Cross"
|
// file="Vector.Cross"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Linear
|
public static unsafe partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float Cross(Vec2 vec1, Vec2 vec2)
|
public static float Cross(Vec2 vec1, Vec2 vec2)
|
||||||
{
|
{
|
||||||
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
|
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec3 Cross(Vec3 vec1, Vec3 vec2)
|
public static Vec3 Cross(Vec3 vec1, Vec3 vec2)
|
||||||
{
|
{
|
||||||
return new Vec3(
|
return new Vec3(
|
||||||
(vec1.Y * vec2.Z) - (vec1.Z * vec2.Y),
|
(vec1.Y * vec2.Z) - (vec1.Z * vec2.Y),
|
||||||
(vec1.X * vec2.Z) - (vec1.Z * vec2.X),
|
(vec1.X * vec2.Z) - (vec1.Z * vec2.X),
|
||||||
(vec1.X * vec2.Y) - (vec1.Y * vec2.X));
|
(vec1.X * vec2.Y) - (vec1.Y * vec2.X));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+47
-47
@@ -1,47 +1,47 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vector.GetAngle"
|
// file="Vector.GetAngle"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Linear
|
public static unsafe partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float GetAngle(Vec2 vec1, Vec2 vec2)
|
public static float GetAngle(Vec2 vec1, Vec2 vec2)
|
||||||
{
|
{
|
||||||
return Scalar.ACos(
|
return Scalar.ACos(
|
||||||
1 / (vec1.GetLength() * vec2.GetLength()));
|
1 / (vec1.GetLength() * vec2.GetLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetAngle(Vec3 vec1, Vec3 vec2)
|
public static float GetAngle(Vec3 vec1, Vec3 vec2)
|
||||||
{
|
{
|
||||||
return Scalar.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
|
return Scalar.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vector.GetLength"
|
// file="Vector.GetLength"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Linear
|
public static unsafe partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float GetLength(this Vec3 vec)
|
public static float GetLength(this Vec3 vec)
|
||||||
{
|
{
|
||||||
return Scalar.Sqrt(vec.Dot(vec));
|
return Scalar.Sqrt(vec.Dot(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetLength(this Vec2 vec)
|
public static float GetLength(this Vec2 vec)
|
||||||
{
|
{
|
||||||
return Scalar.Sqrt(vec.Dot(vec));
|
return Scalar.Sqrt(vec.Dot(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+82
-82
@@ -1,82 +1,82 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vector.Normalize"
|
// file="Vector.Normalize"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
public static partial class Linear
|
public static partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static Vec4 Normalize(Vec4 vec)
|
public static Vec4 Normalize(Vec4 vec)
|
||||||
{
|
{
|
||||||
return new Vec4
|
return new Vec4
|
||||||
{
|
{
|
||||||
vec = Vector4.Normalize(vec.vec)
|
vec = Vector4.Normalize(vec.vec)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec3 Normalize(Vec3 vec)
|
public static Vec3 Normalize(Vec3 vec)
|
||||||
{
|
{
|
||||||
return new Vec3
|
return new Vec3
|
||||||
{
|
{
|
||||||
v = Vector3.Normalize(vec.v)
|
v = Vector3.Normalize(vec.v)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void Normalize(ref Vec4 source, ref Vec4 target)
|
public static unsafe void Normalize(ref Vec4 source, ref Vec4 target)
|
||||||
{
|
{
|
||||||
Vector4 s = source.vec;
|
Vector4 s = source.vec;
|
||||||
Vector4 t = target.vec;
|
Vector4 t = target.vec;
|
||||||
|
|
||||||
s = Vector4.Normalize(s);
|
s = Vector4.Normalize(s);
|
||||||
|
|
||||||
Vector4 projection = Vector4.Multiply(s, t);
|
Vector4 projection = Vector4.Multiply(s, t);
|
||||||
|
|
||||||
t -= projection;
|
t -= projection;
|
||||||
|
|
||||||
source.vec = s;
|
source.vec = s;
|
||||||
target.vec = t;
|
target.vec = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void Normalize(ref Vec3 source, ref Vec3 target)
|
public static unsafe void Normalize(ref Vec3 source, ref Vec3 target)
|
||||||
{
|
{
|
||||||
Vector3 s = source.v;
|
Vector3 s = source.v;
|
||||||
Vector3 t = target.v;
|
Vector3 t = target.v;
|
||||||
|
|
||||||
s = Vector3.Normalize(s);
|
s = Vector3.Normalize(s);
|
||||||
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
|
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
|
||||||
t -= projection;
|
t -= projection;
|
||||||
t = Vector3.Normalize(t);
|
t = Vector3.Normalize(t);
|
||||||
|
|
||||||
source.v = s;
|
source.v = s;
|
||||||
target.v = t;
|
target.v = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+92
-92
@@ -1,92 +1,92 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Vector.Orthogonalize"
|
// file="Vector.Orthogonalize"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics.Graphic;
|
using StgSharp.Mathematics.Graphics;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphic
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
public static partial class Linear
|
public static partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static Vec4 Orthogonalize(this Vec4 vec)
|
public static Vec4 Orthogonalize(this Vec4 vec)
|
||||||
{
|
{
|
||||||
return new Vec4
|
return new Vec4
|
||||||
{
|
{
|
||||||
vec = Vector4.Normalize(vec.vec)
|
vec = Vector4.Normalize(vec.vec)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec3 Orthogonalize(Vec3 vec)
|
public static Vec3 Orthogonalize(Vec3 vec)
|
||||||
{
|
{
|
||||||
return new Vec3
|
return new Vec3
|
||||||
{
|
{
|
||||||
v = Vector3.Normalize(vec.v)
|
v = Vector3.Normalize(vec.v)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void Orthogonalize(this Vec4 source, ref Vec4 target)
|
public static unsafe void Orthogonalize(this Vec4 source, ref Vec4 target)
|
||||||
{
|
{
|
||||||
Vector4 s = source.vec;
|
Vector4 s = source.vec;
|
||||||
Vector4 t = target.vec;
|
Vector4 t = target.vec;
|
||||||
|
|
||||||
s = Vector4.Normalize(s);
|
s = Vector4.Normalize(s);
|
||||||
|
|
||||||
Vector4 projection = Vector4.Multiply(s, t);
|
Vector4 projection = Vector4.Multiply(s, t);
|
||||||
|
|
||||||
t -= projection;
|
t -= projection;
|
||||||
|
|
||||||
source.vec = s;
|
source.vec = s;
|
||||||
target.vec = t;
|
target.vec = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to
|
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to
|
||||||
/// each other.
|
/// each other.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="source">
|
/// <param _label="source">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param _label="target">
|
/// <param _label="target">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
public static unsafe void Orthogonalize(this Vec3 source, ref Vec3 target)
|
public static unsafe void Orthogonalize(this Vec3 source, ref Vec3 target)
|
||||||
{
|
{
|
||||||
Vector3 s = source.v;
|
Vector3 s = source.v;
|
||||||
Vector3 t = target.v;
|
Vector3 t = target.v;
|
||||||
|
|
||||||
s = Vector3.Normalize(s);
|
s = Vector3.Normalize(s);
|
||||||
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
|
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
|
||||||
t -= projection;
|
t -= projection;
|
||||||
t = Vector3.Normalize(t);
|
t = Vector3.Normalize(t);
|
||||||
|
|
||||||
source.v = s;
|
source.v = s;
|
||||||
target.v = t;
|
target.v = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+88
-88
@@ -1,88 +1,88 @@
|
|||||||
# Matrix Coordinate & Naming Conventions (StgSharp)
|
# Matrix Coordinate & Naming Conventions (StgSharp)
|
||||||
|
|
||||||
This document defines the coordinate terminology and naming rules used across `Matrix<T>`, `MatrixKernel<T>`, and packed/triangular storage layouts.
|
This document defines the coordinate terminology and naming rules used across `Matrix<T>`, `MatrixKernel<T>`, and packed/triangular storage layouts.
|
||||||
Goal: eliminate ambiguity around `column`/`row` names (e.g., “index **of** a column” vs “index **along** a column”).
|
Goal: eliminate ambiguity around `column`/`row` names (e.g., “index **of** a column” vs “index **along** a column”).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 1) The key rule: encode prepositions into identifiers (`Of` vs `In`)
|
## 1) The key rule: encode prepositions into identifiers (`Of` vs `In`)
|
||||||
|
|
||||||
### `...OfX` — “which X” (object identity / ordinal)
|
### `...OfX` — “which X” (object identity / ordinal)
|
||||||
Use **`Of`** when the value identifies **which object** (which column, which row, which kernel, etc.).
|
Use **`Of`** when the value identifies **which object** (which column, which row, which kernel, etc.).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
- `columnOfElement`: the element is located in **which column**
|
- `columnOfElement`: the element is located in **which column**
|
||||||
- `rowOfKernel`: the kernel block is located in **which row**
|
- `rowOfKernel`: the kernel block is located in **which row**
|
||||||
|
|
||||||
### `...InX` / `...WithinX` — “inside X” (local coordinate)
|
### `...InX` / `...WithinX` — “inside X” (local coordinate)
|
||||||
Use **`In`** (or `Within`) when the value is a **local coordinate inside** another object.
|
Use **`In`** (or `Within`) when the value is a **local coordinate inside** another object.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
- `columnInKernel`: local column coordinate **inside** a kernel block
|
- `columnInKernel`: local column coordinate **inside** a kernel block
|
||||||
- `rowInKernel`: local row coordinate **inside** a kernel block
|
- `rowInKernel`: local row coordinate **inside** a kernel block
|
||||||
|
|
||||||
> Quick mental model: **`Of` = identity**, **`In` = inside**.
|
> Quick mental model: **`Of` = identity**, **`In` = inside**.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 2) Coordinate levels: `Element`, `KernelGrid`, `InKernel`
|
## 2) Coordinate levels: `Element`, `KernelGrid`, `InKernel`
|
||||||
|
|
||||||
StgSharp commonly uses three coordinate levels:
|
StgSharp commonly uses three coordinate levels:
|
||||||
|
|
||||||
1. **Element-level**: final matrix element coordinates (`Matrix<T>[col,row]`)
|
1. **Element-level**: final matrix element coordinates (`Matrix<T>[col,row]`)
|
||||||
2. **Kernel-grid level**: coordinates of a kernel block in the kernel grid
|
2. **Kernel-grid level**: coordinates of a kernel block in the kernel grid
|
||||||
3. **In-kernel level**: local element coordinates within a kernel (e.g., 4×4)
|
3. **In-kernel level**: local element coordinates within a kernel (e.g., 4×4)
|
||||||
|
|
||||||
Recommended names:
|
Recommended names:
|
||||||
|
|
||||||
| Level | Column name | Row name | Meaning |
|
| Level | Column name | Row name | Meaning |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| Element | `columnOfElement` | `rowOfElement` | element located in which column/row (0-based) |
|
| Element | `columnOfElement` | `rowOfElement` | element located in which column/row (0-based) |
|
||||||
| Kernel grid | `columnOfKernel` | `rowOfKernel` | kernel block located in which kernel-column/kernel-row (0-based) |
|
| Kernel grid | `columnOfKernel` | `rowOfKernel` | kernel block located in which kernel-column/kernel-row (0-based) |
|
||||||
| In-kernel | `columnInKernel` | `rowInKernel` | local coordinate inside the kernel (0..KernelSize-1) |
|
| In-kernel | `columnInKernel` | `rowInKernel` | local coordinate inside the kernel (0..KernelSize-1) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3) Index base: 0-based (mandatory)
|
## 3) Index base: 0-based (mandatory)
|
||||||
|
|
||||||
Unless explicitly documented otherwise, all coordinates are **0-based**:
|
Unless explicitly documented otherwise, all coordinates are **0-based**:
|
||||||
|
|
||||||
- `columnOfElement ∈ [0, ColumnLength-1]`
|
- `columnOfElement ∈ [0, ColumnLength-1]`
|
||||||
- `rowOfElement ∈ [0, RowLength-1]`
|
- `rowOfElement ∈ [0, RowLength-1]`
|
||||||
- `columnOfKernel ∈ [0, KernelColumnLength-1]`
|
- `columnOfKernel ∈ [0, KernelColumnLength-1]`
|
||||||
- `rowOfKernel ∈ [0, KernelRowLength-1]`
|
- `rowOfKernel ∈ [0, KernelRowLength-1]`
|
||||||
- `columnInKernel ∈ [0, KernelSize-1]`
|
- `columnInKernel ∈ [0, KernelSize-1]`
|
||||||
- `rowInKernel ∈ [0, KernelSize-1]`
|
- `rowInKernel ∈ [0, KernelSize-1]`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 4) Mapping element coordinates to kernel coordinates (KernelSize = 4 example)
|
## 4) Mapping element coordinates to kernel coordinates (KernelSize = 4 example)
|
||||||
|
|
||||||
For a fixed kernel size `KernelSize = 4`:
|
For a fixed kernel size `KernelSize = 4`:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
int columnOfKernel = columnOfElement / 4;
|
int columnOfKernel = columnOfElement / 4;
|
||||||
int rowOfKernel = rowOfElement / 4;
|
int rowOfKernel = rowOfElement / 4;
|
||||||
|
|
||||||
int columnInKernel = columnOfElement % 4;
|
int columnInKernel = columnOfElement % 4;
|
||||||
int rowInKernel = rowOfElement % 4;
|
int rowInKernel = rowOfElement % 4;
|
||||||
```
|
```
|
||||||
|
|
||||||
If `columnOfElement` and `rowOfElement` are guaranteed non-negative, bit operations can be used:
|
If `columnOfElement` and `rowOfElement` are guaranteed non-negative, bit operations can be used:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
int columnOfKernel = columnOfElement >> 2;
|
int columnOfKernel = columnOfElement >> 2;
|
||||||
int rowOfKernel = rowOfElement >> 2;
|
int rowOfKernel = rowOfElement >> 2;
|
||||||
|
|
||||||
int columnInKernel = columnOfElement & 3;
|
int columnInKernel = columnOfElement & 3;
|
||||||
int rowInKernel = rowOfElement & 3;
|
int rowInKernel = rowOfElement & 3;
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 5) Packed storage: distinguish `Index` from `Offset`
|
## 5) Packed storage: distinguish `Index` from `Offset`
|
||||||
|
|
||||||
Packed layouts do **not** store “empty blocks”; stored blocks are placed contiguously in a packed buffer.
|
Packed layouts do **not** store “empty blocks”; stored blocks are placed contiguously in a packed buffer.
|
||||||
|
|
||||||
### Use the correct terms
|
### Use the correct terms
|
||||||
- **`packedKernelIndex`**: “the N-th kernel
|
- **`packedKernelIndex`**: “the N-th kernel
|
||||||
+38
-38
@@ -1,38 +1,38 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Cordination"
|
// file="Cordination"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public enum CoordinatePlain
|
public enum CoordinatePlain
|
||||||
{
|
{
|
||||||
|
|
||||||
XY,
|
XY,
|
||||||
YZ,
|
YZ,
|
||||||
XZ,
|
XZ,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IUnmanagedVector"
|
// file="IUnmanagedVector"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public interface IUnmanagedVector<TSelf> where TSelf: unmanaged, IUnmanagedVector<TSelf>
|
public interface IUnmanagedVector<TSelf> where TSelf: unmanaged, IUnmanagedVector<TSelf>
|
||||||
{
|
{
|
||||||
|
|
||||||
public static abstract TSelf Zero { get; }
|
public static abstract TSelf Zero { get; }
|
||||||
|
|
||||||
public static abstract TSelf One { get; }
|
public static abstract TSelf One { get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+101
-101
@@ -1,101 +1,101 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix.Create"
|
// file="Matrix.Create"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public unsafe partial class Matrix<T>
|
public unsafe partial class Matrix<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private const int KernelSideLength = 4;
|
private const int KernelSideLength = 4;
|
||||||
|
|
||||||
public static Matrix<T> Create(
|
public static Matrix<T> Create(
|
||||||
int columnLength,
|
int columnLength,
|
||||||
int rowLength,
|
int rowLength,
|
||||||
MatrixLayout layout,
|
MatrixLayout layout,
|
||||||
HybridLayerSegregatedFitAllocator allocator)
|
HybridLayerSegregatedFitAllocator allocator)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(allocator);
|
ArgumentNullException.ThrowIfNull(allocator);
|
||||||
|
|
||||||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(columnLength);
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(columnLength);
|
||||||
|
|
||||||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(rowLength);
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(rowLength);
|
||||||
|
|
||||||
int kernelColumns = DivideRoundUp(columnLength, KernelSideLength);
|
int kernelColumns = DivideRoundUp(columnLength, KernelSideLength);
|
||||||
int kernelRows = DivideRoundUp(rowLength, KernelSideLength);
|
int kernelRows = DivideRoundUp(rowLength, KernelSideLength);
|
||||||
|
|
||||||
if (layout is MatrixLayout.UpperTriangle or MatrixLayout.LowerTriangle)
|
if (layout is MatrixLayout.UpperTriangle or MatrixLayout.LowerTriangle)
|
||||||
{
|
{
|
||||||
if (kernelColumns != kernelRows) {
|
if (kernelColumns != kernelRows) {
|
||||||
throw new ArgumentException("Triangular layouts require square matrices.");
|
throw new ArgumentException("Triangular layouts require square matrices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long kernelCount = layout switch
|
long kernelCount = layout switch
|
||||||
{
|
{
|
||||||
MatrixLayout.DenseRectangle => (long)kernelColumns * kernelRows,
|
MatrixLayout.DenseRectangle => (long)kernelColumns * kernelRows,
|
||||||
MatrixLayout.UpperTriangle => TriangularKernelCount(kernelColumns),
|
MatrixLayout.UpperTriangle => TriangularKernelCount(kernelColumns),
|
||||||
MatrixLayout.LowerTriangle => TriangularKernelCount(kernelRows),
|
MatrixLayout.LowerTriangle => TriangularKernelCount(kernelRows),
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(layout))
|
_ => throw new ArgumentOutOfRangeException(nameof(layout))
|
||||||
};
|
};
|
||||||
|
|
||||||
long requiredBytes = kernelCount * MatrixKernel<T>.Size;
|
long requiredBytes = kernelCount * MatrixKernel<T>.Size;
|
||||||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(requiredBytes, nameof(requiredBytes));
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(requiredBytes, nameof(requiredBytes));
|
||||||
|
|
||||||
HybridLayerSegregatedFitAllocationHandle handle = allocator.Alloc((uint)requiredBytes);
|
HybridLayerSegregatedFitAllocationHandle handle = allocator.Alloc((uint)requiredBytes);
|
||||||
MatrixStorageHLSF<T> storage = new MatrixStorageHLSF<T>(allocator, handle);
|
MatrixStorageHLSF<T> storage = new MatrixStorageHLSF<T>(allocator, handle);
|
||||||
|
|
||||||
Matrix<T> matrix = new Matrix<T>(MatrixKernelBoarder.Create(layout), new MatrixSize(columnLength, rowLength,
|
Matrix<T> matrix = new Matrix<T>(MatrixKernelBoarder.Create(layout), new MatrixSize(columnLength, rowLength,
|
||||||
kernelColumns,
|
kernelColumns,
|
||||||
kernelRows), storage);
|
kernelRows), storage);
|
||||||
|
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int DivideRoundUp(int value, int divisor)
|
private static int DivideRoundUp(int value, int divisor)
|
||||||
{
|
{
|
||||||
return (value + (divisor - 1)) / divisor;
|
return (value + (divisor - 1)) / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static long TriangularKernelCount(int order)
|
private static long TriangularKernelCount(int order)
|
||||||
{
|
{
|
||||||
long n = order;
|
long n = order;
|
||||||
return (n * (n + 1L)) / 2L;
|
return (n * (n + 1L)) / 2L;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+204
-204
@@ -1,204 +1,204 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix"
|
// file="Matrix"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public unsafe partial class Matrix<T> where T : unmanaged, INumber<T>
|
public unsafe partial class Matrix<T> where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private protected static readonly int t_count = 16 / sizeof(T);
|
private protected static readonly int t_count = 16 / sizeof(T);
|
||||||
|
|
||||||
private protected static readonly int t_size = sizeof(T);
|
private protected static readonly int t_size = sizeof(T);
|
||||||
private readonly MatrixKernelBoarder _boarder;
|
private readonly MatrixKernelBoarder _boarder;
|
||||||
private readonly MatrixSize _size;
|
private readonly MatrixSize _size;
|
||||||
private readonly MatrixStorage<T> _buffer;
|
private readonly MatrixStorage<T> _buffer;
|
||||||
|
|
||||||
private protected Matrix(
|
private protected Matrix(
|
||||||
MatrixKernelBoarder boarder,
|
MatrixKernelBoarder boarder,
|
||||||
MatrixSize size,
|
MatrixSize size,
|
||||||
MatrixStorage<T> buffer
|
MatrixStorage<T> buffer
|
||||||
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_boarder = boarder;
|
_boarder = boarder;
|
||||||
_size = size;
|
_size = size;
|
||||||
_buffer = buffer;
|
_buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T this[
|
public T this[
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
]
|
]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
||||||
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
||||||
}
|
}
|
||||||
long offset = GetElementOffset(x, y);
|
long offset = GetElementOffset(x, y);
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
return T.Zero;
|
return T.Zero;
|
||||||
}
|
}
|
||||||
return ((T*)Buffer)[offset];
|
return ((T*)Buffer)[offset];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
||||||
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
||||||
}
|
}
|
||||||
long offset = GetElementOffset(x, y);
|
long offset = GetElementOffset(x, y);
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
((T*)Buffer)[offset] = value;
|
((T*)Buffer)[offset] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Matlab style indexer to generate a new matrix
|
/// Matlab style indexer to generate a new matrix
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="column">
|
/// <param name="column">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="row">
|
/// <param name="row">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="NotImplementedException">
|
/// <exception cref="NotImplementedException">
|
||||||
///
|
///
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public unsafe Matrix<T> this[
|
public unsafe Matrix<T> this[
|
||||||
ReadOnlySpan<MatrixIndex> column,
|
ReadOnlySpan<MatrixIndex> column,
|
||||||
ReadOnlySpan<MatrixIndex> row
|
ReadOnlySpan<MatrixIndex> row
|
||||||
]
|
]
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get { throw new NotImplementedException(); }
|
||||||
set { throw new NotImplementedException(); }
|
set { throw new NotImplementedException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Length of the matrix in columns.
|
/// Length of the matrix in columns.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ColumnLength => _size.ElementColumnLength;
|
public int ColumnLength => _size.ElementColumnLength;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Length of the matrix in rows.
|
/// Length of the matrix in rows.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RowLength => _size.ElementRowLength;
|
public int RowLength => _size.ElementRowLength;
|
||||||
|
|
||||||
public MatrixLayout Layout { get; init; }
|
public MatrixLayout Layout { get; init; }
|
||||||
|
|
||||||
internal MatrixKernel<T>* Buffer
|
internal MatrixKernel<T>* Buffer
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => (MatrixKernel<T>*)_buffer.BufferPointer;
|
get => (MatrixKernel<T>*)_buffer.BufferPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal int KernelColumnLength => _size.KernelColumnLength;
|
protected internal int KernelColumnLength => _size.KernelColumnLength;
|
||||||
|
|
||||||
protected internal int KernelRowLength => _size.KernelRowLength;
|
protected internal int KernelRowLength => _size.KernelRowLength;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public unsafe ref MatrixKernel<T> GetMatrixKernel(
|
public unsafe ref MatrixKernel<T> GetMatrixKernel(
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return ref _boarder.IsInBuffer(x, y, in _size) ?
|
return ref _boarder.IsInBuffer(x, y, in _size) ?
|
||||||
ref _buffer[_boarder.GetIndexOffset(x, y, in _size)] :
|
ref _buffer[_boarder.GetIndexOffset(x, y, in _size)] :
|
||||||
ref Unsafe.NullRef<MatrixKernel<T>>();
|
ref Unsafe.NullRef<MatrixKernel<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal long GetElementOffset(
|
internal long GetElementOffset(
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int
|
int
|
||||||
k_c = y / 4,
|
k_c = y / 4,
|
||||||
c = y % 4,
|
c = y % 4,
|
||||||
k_r = x / 4,
|
k_r = x / 4,
|
||||||
r = x % 4;
|
r = x % 4;
|
||||||
if (!_boarder.IsInBuffer(k_r, k_c, in _size)) {
|
if (!_boarder.IsInBuffer(k_r, k_c, in _size)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long kernelOffset = _boarder.GetIndexOffset(k_r, k_c, in _size);
|
long kernelOffset = _boarder.GetIndexOffset(k_r, k_c, in _size);
|
||||||
|
|
||||||
return kernelOffset * 16 + 4 * r + c;
|
return kernelOffset * 16 + 4 * r + c;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe ref T GetElementUnsafe(
|
internal unsafe ref T GetElementUnsafe(
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Caller guarantees: indices in range, layout is dense square.
|
// Caller guarantees: indices in range, layout is dense square.
|
||||||
int k_c = y / 4;
|
int k_c = y / 4;
|
||||||
int k_r = x / 4;
|
int k_r = x / 4;
|
||||||
int c = y % 4;
|
int c = y % 4;
|
||||||
int r = x % 4;
|
int r = x % 4;
|
||||||
|
|
||||||
ref MatrixKernel<T> kernel = ref _buffer[_boarder.GetIndexOffset(k_r, k_c, in _size)];
|
ref MatrixKernel<T> kernel = ref _buffer[_boarder.GetIndexOffset(k_r, k_c, in _size)];
|
||||||
return ref kernel[c, r];
|
return ref kernel[c, r];
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe MatrixKernel<T>* GetKernelAddressUnsafe(
|
internal unsafe MatrixKernel<T>* GetKernelAddressUnsafe(
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Buffer + _boarder.GetIndexOffset(x, y, in _size);
|
return Buffer + _boarder.GetIndexOffset(x, y, in _size);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe ref MatrixKernel<T> GetKernelUnsafe(
|
internal unsafe ref MatrixKernel<T> GetKernelUnsafe(
|
||||||
int x,
|
int x,
|
||||||
int y
|
int y
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Caller guarantees: indices in range, layout is dense square.
|
// Caller guarantees: indices in range, layout is dense square.
|
||||||
int k_c = y / 4;
|
int k_c = y / 4;
|
||||||
int k_r = x / 4;
|
int k_r = x / 4;
|
||||||
int c = y % 4;
|
int c = y % 4;
|
||||||
int r = x % 4;
|
int r = x % 4;
|
||||||
return ref _buffer[_boarder.GetIndexOffset(k_c, k_r, in _size)];
|
return ref _buffer[_boarder.GetIndexOffset(k_c, k_r, in _size)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+70
-70
@@ -1,70 +1,70 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixIndex"
|
// file="MatrixIndex"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public readonly struct MatrixIndex
|
public readonly struct MatrixIndex
|
||||||
{
|
{
|
||||||
|
|
||||||
public readonly int Begin;
|
public readonly int Begin;
|
||||||
public readonly int End;
|
public readonly int End;
|
||||||
|
|
||||||
private MatrixIndex(int begin, int end, bool safe = false)
|
private MatrixIndex(int begin, int end, bool safe = false)
|
||||||
{
|
{
|
||||||
Begin = begin;
|
Begin = begin;
|
||||||
End = end;
|
End = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal MatrixIndex(int begin, int end)
|
internal MatrixIndex(int begin, int end)
|
||||||
{
|
{
|
||||||
if (begin > end) {
|
if (begin > end) {
|
||||||
throw new ArgumentException("Begin index cannot be greater than end index.");
|
throw new ArgumentException("Begin index cannot be greater than end index.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Begin = begin;
|
Begin = begin;
|
||||||
End = end;
|
End = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator MatrixIndex((int, int) range)
|
public static implicit operator MatrixIndex((int, int) range)
|
||||||
{
|
{
|
||||||
return new(range.Item1, range.Item2, false);
|
return new(range.Item1, range.Item2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator MatrixIndex(int index)
|
public static implicit operator MatrixIndex(int index)
|
||||||
{
|
{
|
||||||
return new(index, -1, false);
|
return new(index, -1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+252
-252
@@ -1,252 +1,252 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixMetadata"
|
// file="MatrixMetadata"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public enum MatrixLayout
|
public enum MatrixLayout
|
||||||
{
|
{
|
||||||
|
|
||||||
DenseRectangle,
|
DenseRectangle,
|
||||||
UpperTriangle,
|
UpperTriangle,
|
||||||
LowerTriangle,
|
LowerTriangle,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class MatrixKernelBoarder
|
public abstract class MatrixKernelBoarder
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly MatrixKernelBoarder DenseSquareInstance = new DenseSquareKernelBoarder();
|
private static readonly MatrixKernelBoarder DenseSquareInstance = new DenseSquareKernelBoarder();
|
||||||
private static readonly MatrixKernelBoarder LowerTriangleInstance = new LowerTriangleKernelBoarder();
|
private static readonly MatrixKernelBoarder LowerTriangleInstance = new LowerTriangleKernelBoarder();
|
||||||
private static readonly MatrixKernelBoarder UpperTriangleInstance = new UpperTriangleKernelBoarder();
|
private static readonly MatrixKernelBoarder UpperTriangleInstance = new UpperTriangleKernelBoarder();
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static MatrixKernelBoarder Create(
|
public static MatrixKernelBoarder Create(
|
||||||
MatrixLayout layout
|
MatrixLayout layout
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return layout switch
|
return layout switch
|
||||||
{
|
{
|
||||||
MatrixLayout.DenseRectangle => DenseSquareInstance,
|
MatrixLayout.DenseRectangle => DenseSquareInstance,
|
||||||
MatrixLayout.UpperTriangle => UpperTriangleInstance,
|
MatrixLayout.UpperTriangle => UpperTriangleInstance,
|
||||||
MatrixLayout.LowerTriangle => LowerTriangleInstance,
|
MatrixLayout.LowerTriangle => LowerTriangleInstance,
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(layout)),
|
_ => throw new ArgumentOutOfRangeException(nameof(layout)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public abstract long GetIndexOffset(
|
public abstract long GetIndexOffset(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize size
|
in MatrixSize size
|
||||||
);
|
);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public abstract bool IsInBuffer(
|
public abstract bool IsInBuffer(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
);
|
);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
protected static long GetTriangularOrder(
|
protected static long GetTriangularOrder(
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Math.Min(enumerator.KernelColumnLength, enumerator.KernelRowLength);
|
return Math.Min(enumerator.KernelColumnLength, enumerator.KernelRowLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
protected static bool IsWithinKernelDomain(
|
protected static bool IsWithinKernelDomain(
|
||||||
in MatrixSize enumerator,
|
in MatrixSize enumerator,
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel
|
int yKernel
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return xKernel >= 0 &&
|
return xKernel >= 0 &&
|
||||||
yKernel >= 0 &&
|
yKernel >= 0 &&
|
||||||
xKernel < enumerator.KernelColumnLength &&
|
xKernel < enumerator.KernelColumnLength &&
|
||||||
yKernel < enumerator.KernelRowLength;
|
yKernel < enumerator.KernelRowLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
protected static bool IsWithinTriangularDomain(
|
protected static bool IsWithinTriangularDomain(
|
||||||
in MatrixSize enumerator,
|
in MatrixSize enumerator,
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel
|
int yKernel
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long order = GetTriangularOrder(enumerator);
|
long order = GetTriangularOrder(enumerator);
|
||||||
return xKernel >= 0 && yKernel >= 0 && xKernel < order && yKernel < order;
|
return xKernel >= 0 && yKernel >= 0 && xKernel < order && yKernel < order;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class DenseSquareKernelBoarder : MatrixKernelBoarder
|
private sealed class DenseSquareKernelBoarder : MatrixKernelBoarder
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override long GetIndexOffset(
|
public override long GetIndexOffset(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long x = xKernel;
|
long x = xKernel;
|
||||||
long y = yKernel;
|
long y = yKernel;
|
||||||
long col = enumerator.KernelColumnLength;
|
long col = enumerator.KernelColumnLength;
|
||||||
|
|
||||||
// Console.Write($"Attempt to get offset at ({x},{y}), offset is {x * col + y} ");
|
// Console.Write($"Attempt to get offset at ({x},{y}), offset is {x * col + y} ");
|
||||||
return x * col + y;
|
return x * col + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override bool IsInBuffer(
|
public override bool IsInBuffer(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return IsWithinKernelDomain(enumerator, xKernel, yKernel);
|
return IsWithinKernelDomain(enumerator, xKernel, yKernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class LowerTriangleKernelBoarder : MatrixKernelBoarder
|
private sealed class LowerTriangleKernelBoarder : MatrixKernelBoarder
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override long GetIndexOffset(
|
public override long GetIndexOffset(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long order = GetTriangularOrder(enumerator);
|
long order = GetTriangularOrder(enumerator);
|
||||||
long x = xKernel;
|
long x = xKernel;
|
||||||
long y = yKernel;
|
long y = yKernel;
|
||||||
|
|
||||||
long prefixColumns = x * order - (x * (x - 1L)) / 2L;
|
long prefixColumns = x * order - (x * (x - 1L)) / 2L;
|
||||||
return prefixColumns + (y - x);
|
return prefixColumns + (y - x);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override bool IsInBuffer(
|
public override bool IsInBuffer(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return IsWithinTriangularDomain(enumerator, xKernel, yKernel) && yKernel >= xKernel;
|
return IsWithinTriangularDomain(enumerator, xKernel, yKernel) && yKernel >= xKernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed unsafe class UpperTriangleKernelBoarder : MatrixKernelBoarder
|
private sealed unsafe class UpperTriangleKernelBoarder : MatrixKernelBoarder
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override long GetIndexOffset(
|
public override long GetIndexOffset(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long x = xKernel;
|
long x = xKernel;
|
||||||
long y = yKernel;
|
long y = yKernel;
|
||||||
|
|
||||||
long prefixColumns = (x * (x + 1L)) / 2L;
|
long prefixColumns = (x * (x + 1L)) / 2L;
|
||||||
return prefixColumns + y;
|
return prefixColumns + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override bool IsInBuffer(
|
public override bool IsInBuffer(
|
||||||
int xKernel,
|
int xKernel,
|
||||||
int yKernel,
|
int yKernel,
|
||||||
in MatrixSize enumerator
|
in MatrixSize enumerator
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return IsWithinTriangularDomain(enumerator, xKernel, yKernel) && yKernel <= xKernel;
|
return IsWithinTriangularDomain(enumerator, xKernel, yKernel) && yKernel <= xKernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
public struct MatrixSize
|
public struct MatrixSize
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] public readonly int ElementColumnLength;
|
[FieldOffset(0)] public readonly int ElementColumnLength;
|
||||||
[FieldOffset(4)] public readonly int ElementRowLength;
|
[FieldOffset(4)] public readonly int ElementRowLength;
|
||||||
|
|
||||||
[FieldOffset(8)] public readonly int KernelColumnLength;
|
[FieldOffset(8)] public readonly int KernelColumnLength;
|
||||||
[FieldOffset(12)] public readonly int KernelRowLength;
|
[FieldOffset(12)] public readonly int KernelRowLength;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public MatrixSize(
|
public MatrixSize(
|
||||||
int elementColumnLength,
|
int elementColumnLength,
|
||||||
int elementRowLength,
|
int elementRowLength,
|
||||||
int kernelColumnLength,
|
int kernelColumnLength,
|
||||||
int kernelRowLength
|
int kernelRowLength
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ElementColumnLength = elementColumnLength;
|
ElementColumnLength = elementColumnLength;
|
||||||
ElementRowLength = elementRowLength;
|
ElementRowLength = elementRowLength;
|
||||||
KernelColumnLength = kernelColumnLength;
|
KernelColumnLength = kernelColumnLength;
|
||||||
KernelRowLength = kernelRowLength;
|
KernelRowLength = kernelRowLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
public struct MatrixKernelEnumerator
|
public struct MatrixKernelEnumerator
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] public int CurrentColumn;
|
[FieldOffset(0)] public int CurrentColumn;
|
||||||
[FieldOffset(4)] public int CurrentRow;
|
[FieldOffset(4)] public int CurrentRow;
|
||||||
|
|
||||||
[FieldOffset(8)] public readonly int KernelColumnLength;
|
[FieldOffset(8)] public readonly int KernelColumnLength;
|
||||||
[FieldOffset(12)] public readonly int KernelRowLength;
|
[FieldOffset(12)] public readonly int KernelRowLength;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public MatrixKernelEnumerator(
|
public MatrixKernelEnumerator(
|
||||||
int kernelColumnLength,
|
int kernelColumnLength,
|
||||||
int kernelRowLength,
|
int kernelRowLength,
|
||||||
int currentColumn = 0,
|
int currentColumn = 0,
|
||||||
int currentRow = 0
|
int currentRow = 0
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CurrentColumn = currentColumn;
|
CurrentColumn = currentColumn;
|
||||||
CurrentRow = currentRow;
|
CurrentRow = currentRow;
|
||||||
KernelColumnLength = kernelColumnLength;
|
KernelColumnLength = kernelColumnLength;
|
||||||
KernelRowLength = kernelRowLength;
|
KernelRowLength = kernelRowLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+72
-72
@@ -1,72 +1,72 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixStorage"
|
// file="MatrixStorage"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using HLSFAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
using HLSFAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
||||||
using HLSFHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
using HLSFHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public abstract class MatrixStorage<T> : IDisposable where T : unmanaged, INumber<T>
|
public abstract class MatrixStorage<T> : IDisposable where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
internal unsafe ref MatrixKernel<T> this[long index]
|
internal unsafe ref MatrixKernel<T> this[long index]
|
||||||
{
|
{
|
||||||
get { return ref Unsafe.AsRef<MatrixKernel<T>>(BufferPointer + MatrixKernel<T>.Size * index); }
|
get { return ref Unsafe.AsRef<MatrixKernel<T>>(BufferPointer + MatrixKernel<T>.Size * index); }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal abstract unsafe T* BufferPointer { get; }
|
protected internal abstract unsafe T* BufferPointer { get; }
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class MatrixStorageHLSF<T>(HLSFAllocator allocator, HLSFHandle handle) : MatrixStorage<T>
|
internal class MatrixStorageHLSF<T>(HLSFAllocator allocator, HLSFHandle handle) : MatrixStorage<T>
|
||||||
where T : unmanaged, INumber<T>
|
where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
internal HLSFAllocator _allocator = allocator;
|
internal HLSFAllocator _allocator = allocator;
|
||||||
internal HLSFHandle _handle = handle;
|
internal HLSFHandle _handle = handle;
|
||||||
|
|
||||||
protected internal override unsafe T* BufferPointer => (T*)_handle.Pointer;
|
protected internal override unsafe T* BufferPointer => (T*)_handle.Pointer;
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
allocator.Free(_handle);
|
allocator.Free(_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
@@ -112,7 +112,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
package->ElementSize = sizeof(float);
|
package->ElementSize = sizeof(float);
|
||||||
package->PrimCount = ans.KernelColumnLength;
|
package->PrimCount = ans.KernelColumnLength;
|
||||||
@@ -178,7 +178,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
@@ -231,7 +231,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Right = (nint)left.Buffer;
|
package->Right = (nint)left.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
package->ElementSize = sizeof(float);
|
package->ElementSize = sizeof(float);
|
||||||
@@ -287,7 +287,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
@@ -108,7 +108,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
package->ElementSize = sizeof(double);
|
package->ElementSize = sizeof(double);
|
||||||
package->PrimCount = ans.KernelColumnLength;
|
package->PrimCount = ans.KernelColumnLength;
|
||||||
@@ -167,7 +167,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
@@ -220,7 +220,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Right = (nint)left.Buffer;
|
package->Right = (nint)left.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
package->ElementSize = sizeof(double);
|
package->ElementSize = sizeof(double);
|
||||||
@@ -276,7 +276,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask();
|
MatrixParallelTask* package = MatrixParallelFactory.CreateBaseTask();
|
||||||
package->Left = (nint)left.Buffer;
|
package->Left = (nint)left.Buffer;
|
||||||
package->Right = (nint)right.Buffer;
|
package->Right = (nint)right.Buffer;
|
||||||
package->Answer = (nint)ans.Buffer;
|
package->Answer = (nint)ans.Buffer;
|
||||||
|
|||||||
@@ -1,147 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="MatrixParallelTaskPackage"
|
|
||||||
// Project: StgSharp
|
|
||||||
// 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
|
|
||||||
// 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 StgSharp.HighPerformance;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* #define PANEL_OP 1
|
|
||||||
* #define BUFFER_OP 2
|
|
||||||
* #define KERNEL_OP 3
|
|
||||||
*
|
|
||||||
* #define RIGHT_ANS_PARAM 1
|
|
||||||
* #define LEFT_RIGHT_ANS_PARAM 2
|
|
||||||
* #define RIGHT_ANS_SCALAR_PARAM 3
|
|
||||||
* #define LEFT_RIGHT_ANS_SCALAR_PARAM 4
|
|
||||||
* #define ANS_SCALAR_PARAM 5
|
|
||||||
*
|
|
||||||
* typedef struct matrix_op_mode {
|
|
||||||
* int16_t operation_style; // PANEL_OP, BUFFER_OP, KERNEL_OP
|
|
||||||
* int16_t parameter_style; // RIGHT_ANS_PARAM, LEFT_RIGHT_ANS_PARAM, e.g.
|
|
||||||
* }
|
|
||||||
* matrix_op_mode;
|
|
||||||
*/
|
|
||||||
|
|
||||||
public enum MatrixIndexStyle : int
|
|
||||||
{
|
|
||||||
|
|
||||||
NONE = 0,
|
|
||||||
BUFFER_INDEX = 1,
|
|
||||||
SEQ_FMA = -1,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 128)]
|
|
||||||
public unsafe struct MatrixParallelTaskPackage
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe void Copy(
|
|
||||||
MatrixParallelTaskPackage* source,
|
|
||||||
MatrixParallelTaskPackage* target
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage),
|
|
||||||
sizeof(MatrixParallelTaskPackage));
|
|
||||||
}
|
|
||||||
|
|
||||||
#region source
|
|
||||||
|
|
||||||
// Group 1: Left/Right matrix kernel base address
|
|
||||||
[FieldOffset(0)] public IntPtr Left; // 8
|
|
||||||
[FieldOffset(8)] public IntPtr Right; // 8
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ans
|
|
||||||
|
|
||||||
// Group 2: Result kernel base address + reserved
|
|
||||||
[FieldOffset(16)] public IntPtr Answer; // 8
|
|
||||||
[FieldOffset(24)] public int ElementSize;
|
|
||||||
[FieldOffset(28)] public int ReservedPtr0; // 4 (extension/reserved)
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region left enum
|
|
||||||
|
|
||||||
[FieldOffset(32)]public int LeftPrimOffset; // 4
|
|
||||||
[FieldOffset(36)]public int LeftPrimStride; // 4
|
|
||||||
[FieldOffset(40)]public int LeftSecOffset; // 4
|
|
||||||
[FieldOffset(44)]public int LeftSecStride; // 4
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region right enum
|
|
||||||
|
|
||||||
[FieldOffset(48)]public int RightPrimOffset; // 4
|
|
||||||
[FieldOffset(52)]public int RightPrimStride; // 4
|
|
||||||
[FieldOffset(56)]public int RightSecOffset; // 4
|
|
||||||
[FieldOffset(60)]public int RightSecStride; // 4
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ans enum
|
|
||||||
|
|
||||||
[FieldOffset(64)]public int AnsPrimOffset; // 4
|
|
||||||
[FieldOffset(68)]public int AnsPrimStride; // 4
|
|
||||||
[FieldOffset(72)]public int AnsSecOffset; // 4
|
|
||||||
[FieldOffset(76)] public int AnsSecStride; // 4
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region scalar/compute
|
|
||||||
|
|
||||||
[FieldOffset(80)]public ScalarPacket* Scalar; // 8
|
|
||||||
[FieldOffset(88)]public IntPtr ComputeHandle; // 8
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region global profile
|
|
||||||
|
|
||||||
[FieldOffset(96)]public int PrimCount; // 4
|
|
||||||
[FieldOffset(100)]public int SecCount; // 4
|
|
||||||
[FieldOffset(104)]public MatrixIndexStyle ComputeMode; // 4
|
|
||||||
[FieldOffset(108)]private int ReservedInt0; // 4
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region count offset
|
|
||||||
|
|
||||||
[FieldOffset(112)]public int PrimTileOffset; // 4
|
|
||||||
[FieldOffset(116)]public int SecTileOffset; // 4
|
|
||||||
[FieldOffset(120)] public int PrimColumnCountInTile; // 4
|
|
||||||
[FieldOffset(124)] public int SecColumnCountInTile; // 4
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+146
-146
@@ -1,146 +1,146 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.Await"
|
// file="MatrixParallel.Await"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public static partial class MatrixParallel
|
public static partial class MatrixParallel
|
||||||
{
|
{
|
||||||
|
|
||||||
private static AwaitingQueue _awaitingLeaderHandle;
|
private static AwaitingQueue _awaitingLeaderHandle;
|
||||||
|
|
||||||
private static volatile int _createGeneration = 0;
|
private static volatile int _createGeneration = 0;
|
||||||
private static int _sortState;
|
private static int _sortState;
|
||||||
|
|
||||||
public static MatrixParallelThread[] LeadParallel(int recommendCount)
|
public static MatrixParallelThread[] LeadParallel(int recommendCount)
|
||||||
{
|
{
|
||||||
int min = int.Min(recommendCount, _threads.Capacity);
|
int min = int.Min(recommendCount, _threads.Capacity);
|
||||||
min /= 2;
|
min /= 2;
|
||||||
MatrixParallelThread[] ret;
|
MatrixParallelThread[] ret;
|
||||||
if (_threads.Count < min)
|
if (_threads.Count < min)
|
||||||
{
|
{
|
||||||
WaitHandle handle = new WaitHandle
|
WaitHandle handle = new WaitHandle
|
||||||
(
|
(
|
||||||
_createGeneration,
|
_createGeneration,
|
||||||
min,
|
min,
|
||||||
recommendCount
|
recommendCount
|
||||||
);
|
);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
||||||
{
|
{
|
||||||
_awaitingLeaderHandle.Enqueue(handle);
|
_awaitingLeaderHandle.Enqueue(handle);
|
||||||
_ = Interlocked.Exchange(ref _sortState, 0);
|
_ = Interlocked.Exchange(ref _sortState, 0);
|
||||||
Interlocked.Increment(ref _createGeneration);
|
Interlocked.Increment(ref _createGeneration);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
int cycleGeneration = _createGeneration;
|
int cycleGeneration = _createGeneration;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Thread.Sleep(0);
|
Thread.Sleep(0);
|
||||||
|
|
||||||
if (_createGeneration != cycleGeneration)
|
if (_createGeneration != cycleGeneration)
|
||||||
{
|
{
|
||||||
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
||||||
{
|
{
|
||||||
if (_awaitingLeaderHandle.TryPopIfRefEqual(cycleGeneration, in handle))
|
if (_awaitingLeaderHandle.TryPopIfRefEqual(cycleGeneration, in handle))
|
||||||
{
|
{
|
||||||
// Sort is implemented in TryPopIfRefEqual
|
// Sort is implemented in TryPopIfRefEqual
|
||||||
ret = _threads.PopRange(handle.BestCount);
|
ret = _threads.PopRange(handle.BestCount);
|
||||||
_createGeneration++;
|
_createGeneration++;
|
||||||
_ = Interlocked.Exchange(ref _sortState, 0);
|
_ = Interlocked.Exchange(ref _sortState, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
_ = Interlocked.Exchange(ref _sortState, 0);
|
_ = Interlocked.Exchange(ref _sortState, 0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
cycleGeneration = _createGeneration;
|
cycleGeneration = _createGeneration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// directly get the leader
|
// directly get the leader
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
||||||
{
|
{
|
||||||
ret = _threads.PopRange(recommendCount);
|
ret = _threads.PopRange(recommendCount);
|
||||||
_createGeneration++;
|
_createGeneration++;
|
||||||
_ = Interlocked.Exchange(ref _sortState, 0);
|
_ = Interlocked.Exchange(ref _sortState, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return ret;
|
// return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReturnParallelResources(ref MatrixParallelThread[] pool)
|
public static void ReturnParallelResources(ref MatrixParallelThread[] pool)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
if (Interlocked.Exchange(ref _sortState, 1) == 0)
|
||||||
{
|
{
|
||||||
_threads.PushRange(pool);
|
_threads.PushRange(pool);
|
||||||
Interlocked.Exchange(ref _sortState, 0);
|
Interlocked.Exchange(ref _sortState, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pool = null!;
|
pool = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record class WaitHandle(int generation, int least, int best)
|
private record class WaitHandle(int generation, int least, int best)
|
||||||
{
|
{
|
||||||
|
|
||||||
public int CreateGeneration { get; init; } = generation;
|
public int CreateGeneration { get; init; } = generation;
|
||||||
|
|
||||||
public int LeastCount { get; init; } = least;
|
public int LeastCount { get; init; } = least;
|
||||||
|
|
||||||
public int BestCount { get; init; } = best;
|
public int BestCount { get; init; } = best;
|
||||||
|
|
||||||
public int Priority { get; private set; }
|
public int Priority { get; private set; }
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void UpdatePriority(int currentGeneration)
|
public void UpdatePriority(int currentGeneration)
|
||||||
{
|
{
|
||||||
Priority = (currentGeneration - CreateGeneration) * (MatrixParallel._threads.Capacity - LeastCount);
|
Priority = (currentGeneration - CreateGeneration) * (MatrixParallel._threads.Capacity - LeastCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+156
-156
@@ -1,156 +1,156 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.AwaitingQueue"
|
// file="MatrixParallel.AwaitingQueue"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public static partial class MatrixParallel
|
public static partial class MatrixParallel
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Because caller of this class has its own sync object
|
* Because caller of this class has its own sync object
|
||||||
* this queue will use no sync object internally.
|
* this queue will use no sync object internally.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private class AwaitingQueue
|
private class AwaitingQueue
|
||||||
{
|
{
|
||||||
|
|
||||||
private Element _quickElements = new();
|
private Element _quickElements = new();
|
||||||
private volatile int _count;
|
private volatile int _count;
|
||||||
private readonly Queue<WaitHandle> _fallback = [];
|
private readonly Queue<WaitHandle> _fallback = [];
|
||||||
|
|
||||||
public AwaitingQueue() { }
|
public AwaitingQueue() { }
|
||||||
|
|
||||||
public void Enqueue(WaitHandle handle)
|
public void Enqueue(WaitHandle handle)
|
||||||
{
|
{
|
||||||
if (_count > 7)
|
if (_count > 7)
|
||||||
{
|
{
|
||||||
_fallback.Enqueue(handle);
|
_fallback.Enqueue(handle);
|
||||||
Interlocked.Increment(ref _count);
|
Interlocked.Increment(ref _count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_quickElements[_count] = handle;
|
_quickElements[_count] = handle;
|
||||||
Interlocked.Increment(ref _count);
|
Interlocked.Increment(ref _count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryDequeue(int generation, out WaitHandle handle)
|
public bool TryDequeue(int generation, out WaitHandle handle)
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
if (_count == 0)
|
||||||
{
|
{
|
||||||
handle = null!;
|
handle = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
_quickElements[i].UpdatePriority(generation);
|
_quickElements[i].UpdatePriority(generation);
|
||||||
}
|
}
|
||||||
Element.Sort(ref _quickElements);
|
Element.Sort(ref _quickElements);
|
||||||
handle = _quickElements[0];
|
handle = _quickElements[0];
|
||||||
_count--;
|
_count--;
|
||||||
_quickElements[0] = default!;
|
_quickElements[0] = default!;
|
||||||
if (_count > 7) {
|
if (_count > 7) {
|
||||||
_ = _fallback.TryDequeue(out _quickElements[0]!);
|
_ = _fallback.TryDequeue(out _quickElements[0]!);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryPeek(int generation, out WaitHandle handle)
|
public bool TryPeek(int generation, out WaitHandle handle)
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
if (_count == 0)
|
||||||
{
|
{
|
||||||
handle = null!;
|
handle = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
_quickElements[i].UpdatePriority(generation);
|
_quickElements[i].UpdatePriority(generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element.Sort(ref _quickElements);
|
Element.Sort(ref _quickElements);
|
||||||
handle = _quickElements[0];
|
handle = _quickElements[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryPopIfRefEqual(int generation, in WaitHandle handle)
|
public bool TryPopIfRefEqual(int generation, in WaitHandle handle)
|
||||||
{
|
{
|
||||||
if (_count == 0) {
|
if (_count == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
_quickElements[i].UpdatePriority(generation);
|
_quickElements[i].UpdatePriority(generation);
|
||||||
}
|
}
|
||||||
Element.Sort(ref _quickElements);
|
Element.Sort(ref _quickElements);
|
||||||
if (!ReferenceEquals(_quickElements[0], handle)) {
|
if (!ReferenceEquals(_quickElements[0], handle)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_count--;
|
_count--;
|
||||||
_quickElements[0] = null!;
|
_quickElements[0] = null!;
|
||||||
if (_count > 7) {
|
if (_count > 7) {
|
||||||
_ = _fallback.TryDequeue(out _quickElements[0]!);
|
_ = _fallback.TryDequeue(out _quickElements[0]!);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[InlineArray(8)]
|
[InlineArray(8)]
|
||||||
private struct Element
|
private struct Element
|
||||||
{
|
{
|
||||||
|
|
||||||
private WaitHandle value;
|
private WaitHandle value;
|
||||||
|
|
||||||
public static void Sort(ref Element e)
|
public static void Sort(ref Element e)
|
||||||
{
|
{
|
||||||
int maxIdx = 0;
|
int maxIdx = 0;
|
||||||
WaitHandle first = e[0];
|
WaitHandle first = e[0];
|
||||||
int maxPr = first?.Priority ?? int.MinValue;
|
int maxPr = first?.Priority ?? int.MinValue;
|
||||||
|
|
||||||
for (int i = 1; i < 8; i++)
|
for (int i = 1; i < 8; i++)
|
||||||
{
|
{
|
||||||
WaitHandle cur = e[i];
|
WaitHandle cur = e[i];
|
||||||
int p = cur?.Priority ?? int.MinValue;
|
int p = cur?.Priority ?? int.MinValue;
|
||||||
if (p > maxPr)
|
if (p > maxPr)
|
||||||
{
|
{
|
||||||
maxPr = p;
|
maxPr = p;
|
||||||
maxIdx = i;
|
maxIdx = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxIdx != 0) {
|
if (maxIdx != 0) {
|
||||||
(e[0], e[maxIdx]) = (e[maxIdx], e[0]);
|
(e[0], e[maxIdx]) = (e[maxIdx], e[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+80
-80
@@ -1,80 +1,80 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.Publish"
|
// file="MatrixParallel.Publish"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Collections;
|
using StgSharp.Collections;
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public static partial class MatrixParallel
|
public static partial class MatrixParallel
|
||||||
{
|
{
|
||||||
|
|
||||||
private const int MIN_TASK_PER_THREAD = 256;
|
private const int MIN_TASK_PER_THREAD = 256;
|
||||||
private const int REC_TASK_PER_THREAD = 1024;
|
private const int REC_TASK_PER_THREAD = 1024;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
||||||
internal static unsafe MatrixParallelWrap ScheduleTask(
|
internal static unsafe MatrixParallelWrap ScheduleTask(
|
||||||
MatrixParallelTaskPackage* package
|
MatrixParallelTask* package
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch (package->ComputeMode.OperationStyle)
|
switch (package->ComputeMode.OperationStyle)
|
||||||
{
|
{
|
||||||
case MatrixIndexStyle.BUFFER_INDEX:
|
case MatrixIndexStyle.BUFFER_INDEX:
|
||||||
return ScheduleBufferTask(package);
|
return ScheduleBufferTask(package);
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException($"Unknown mode {package->ComputeMode.OperationStyle}.");
|
throw new InvalidOperationException($"Unknown mode {package->ComputeMode.OperationStyle}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static unsafe MatrixParallelWrap ScheduleBufferTask(
|
private static unsafe MatrixParallelWrap ScheduleBufferTask(
|
||||||
MatrixParallelTaskPackage* package
|
MatrixParallelTask* package
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int primCount = package->PrimCount;
|
int primCount = package->PrimCount;
|
||||||
int secCount = package->SecCount;
|
int secCount = package->SecCount;
|
||||||
long count = (long)primCount * secCount;
|
long count = (long)primCount * secCount;
|
||||||
|
|
||||||
// Console.WriteLine($"amount of kernels is {count}");
|
// Console.WriteLine($"amount of kernels is {count}");
|
||||||
|
|
||||||
long recommendCount = count / 1024;
|
long recommendCount = count / 1024;
|
||||||
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
|
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
|
||||||
MatrixParallelWrap wrap = new MatrixParallelWrap(pool);
|
MatrixParallelWrap wrap = new MatrixParallelWrap(pool);
|
||||||
wrap.TaskQueue = MatrixParallelQueue.Rent(package);
|
wrap.TaskQueue = MatrixParallelQueue.Rent(package);
|
||||||
return wrap;
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+132
-132
@@ -1,132 +1,132 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel"
|
// file="MatrixParallel"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Collections;
|
using StgSharp.Collections;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
using StgSharp.Internal;
|
using StgSharp.Internal;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Mathematics.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public static partial class MatrixParallel
|
public static partial class MatrixParallel
|
||||||
{
|
{
|
||||||
|
|
||||||
private static bool _meaningful;
|
private static bool _meaningful;
|
||||||
|
|
||||||
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
||||||
|
|
||||||
private static ConcurrentDictionary<SIMDID, nint> contextMap;
|
private static ConcurrentDictionary<SIMDID, nint> contextMap;
|
||||||
|
|
||||||
private static SlabAllocator<IntrinsicContext> contextAllocator;
|
private static SlabAllocator<IntrinsicContext> contextAllocator;
|
||||||
|
|
||||||
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
|
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
|
||||||
|
|
||||||
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
|
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
|
||||||
|
|
||||||
private static bool IsInitialized { get; set; } = false;
|
private static bool IsInitialized { get; set; } = false;
|
||||||
|
|
||||||
internal static unsafe IntrinsicContext* GetContext(
|
internal static unsafe IntrinsicContext* GetContext(
|
||||||
SIMDID simd
|
SIMDID simd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!IsParallelSupported) {
|
if (!IsParallelSupported) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (contextMap.TryGetValue(simd, out nint handle))
|
if (contextMap.TryGetValue(simd, out nint handle))
|
||||||
{
|
{
|
||||||
return (IntrinsicContext*)handle;
|
return (IntrinsicContext*)handle;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
IntrinsicContext* context = (IntrinsicContext*)contextAllocator.Allocate();
|
IntrinsicContext* context = (IntrinsicContext*)contextAllocator.Allocate();
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Init()
|
internal static void Init()
|
||||||
{
|
{
|
||||||
if (IsInitialized) {
|
if (IsInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!IsParallelSupported)
|
if (!IsParallelSupported)
|
||||||
{
|
{
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallelFactory.Init();
|
MatrixParallelFactory.Init();
|
||||||
contextAllocator = SlabAllocator<IntrinsicContext>.Create(4, SlabBufferLayout.Chunked, false);
|
contextAllocator = SlabAllocator<IntrinsicContext>.Create(4, SlabBufferLayout.Chunked, false);
|
||||||
contextMap = [];
|
contextMap = [];
|
||||||
int count = Environment.ProcessorCount;
|
int count = Environment.ProcessorCount;
|
||||||
_threads = new(count);
|
_threads = new(count);
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
MatrixParallelThread thread = new MatrixParallelThread(i);
|
MatrixParallelThread thread = new MatrixParallelThread(i);
|
||||||
_threads.Push(thread);
|
_threads.Push(thread);
|
||||||
SpinWait.SpinUntil(() => thread.State == MatrixThreadState.Ready);
|
SpinWait.SpinUntil(() => thread.State == MatrixThreadState.Ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 构建全局的保底上下文
|
// TODO 构建全局的保底上下文
|
||||||
foreach (MatrixParallelThread thread in _threads) { }
|
foreach (MatrixParallelThread thread in _threads) { }
|
||||||
if (contextMap.Keys.Count == 1)
|
if (contextMap.Keys.Count == 1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
MatrixParallelThread thread = _threads.Pop();
|
MatrixParallelThread thread = _threads.Pop();
|
||||||
thread.Dispose();
|
thread.Dispose();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// TODO 排序并丢弃四个能力最弱线程
|
// TODO 排序并丢弃四个能力最弱线程
|
||||||
}
|
}
|
||||||
_awaitingLeaderHandle = new AwaitingQueue();
|
_awaitingLeaderHandle = new AwaitingQueue();
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "sn_compare_simd")]
|
[LibraryImport(Native.LibName, EntryPoint = "sn_compare_simd")]
|
||||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
private static unsafe partial ulong CompareSIMDID(
|
private static unsafe partial ulong CompareSIMDID(
|
||||||
IntrinsicContext* context,
|
IntrinsicContext* context,
|
||||||
ulong id
|
ulong id
|
||||||
);
|
);
|
||||||
|
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
private static unsafe partial void LoadIntrinsicFunction(
|
private static unsafe partial void LoadIntrinsicFunction(
|
||||||
IntrinsicContext* context,
|
IntrinsicContext* context,
|
||||||
ulong id
|
ulong id
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -40,16 +40,16 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
|
|
||||||
private static ConcurrentStack<MatrixParallelQueue> _recycle = [];
|
private static ConcurrentStack<MatrixParallelQueue> _recycle = [];
|
||||||
private MatrixParallelTaskPackage* _package;
|
private MatrixParallelTask* _package;
|
||||||
private ulong _cursor;
|
private ulong _cursor;
|
||||||
private ulong _maxCount;
|
private ulong _maxCount;
|
||||||
|
|
||||||
private MatrixParallelQueue() { }
|
private MatrixParallelQueue() { }
|
||||||
|
|
||||||
public MatrixParallelTaskPackage* Package => _package;
|
public MatrixParallelTask* Package => _package;
|
||||||
|
|
||||||
public static MatrixParallelQueue Rent(
|
public static MatrixParallelQueue Rent(
|
||||||
MatrixParallelTaskPackage* pack
|
MatrixParallelTask* pack
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!_recycle.TryPop(out MatrixParallelQueue? queue)) {
|
if (!_recycle.TryPop(out MatrixParallelQueue? queue)) {
|
||||||
+64
-68
@@ -1,68 +1,64 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="SSDraw"
|
// file="MatrixParallelTask"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Graphics.ShaderEdit;
|
using StgSharp.HighPerformance;
|
||||||
|
using StgSharp.Mathematics.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Numerics;
|
||||||
using System.Collections.Generic;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Globalization;
|
using System.Runtime.InteropServices;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
namespace StgSharp.Mathematics.Numeric
|
||||||
using System.Numerics;
|
{
|
||||||
using System.Runtime.CompilerServices;
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
using System.Runtime.InteropServices;
|
internal unsafe struct MatrixParallelTask
|
||||||
using System.Security.Cryptography;
|
{
|
||||||
using System.Text;
|
|
||||||
using System.Xml.Serialization;
|
[FieldOffset(0)]public MatrixKernel* Mat1; // 8
|
||||||
|
[FieldOffset(8)] public MatrixKernel* Mat2; // 8
|
||||||
namespace StgSharp.Internal.FileIO
|
[FieldOffset(16)] public MatrixKernel* Mat3; // 16
|
||||||
{
|
[FieldOffset(32)] public int Common_i;
|
||||||
public class SSDraw
|
[FieldOffset(36)] public int Common_j;
|
||||||
{
|
[FieldOffset(40)] public int Common_k;
|
||||||
|
[FieldOffset(44)] public int i;
|
||||||
private byte[] data;
|
[FieldOffset(48)] public int j;
|
||||||
|
[FieldOffset(52)] public int k;
|
||||||
public SSDraw(string name, Stream streamSource)
|
[FieldOffset(56)] public MatrixElementType ElementType; // 56
|
||||||
{
|
[FieldOffset(24)] public nint Span; // 24
|
||||||
if ((streamSource == null) || (streamSource.Length == 0)) {
|
|
||||||
throw new ArgumentNullException(nameof(streamSource));
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
}
|
public static void Copy(
|
||||||
Name = name;
|
MatrixParallelTask* source,
|
||||||
data = new byte[streamSource.Length];
|
MatrixParallelTask* target
|
||||||
streamSource.Read(data.AsSpan());
|
)
|
||||||
}
|
{
|
||||||
|
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTask),
|
||||||
public SSDrawHead Head { get; set; }
|
sizeof(MatrixParallelTask));
|
||||||
|
}
|
||||||
public string Name { get; set; }
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
|
||||||
public unsafe struct SSDrawHead { }
|
|
||||||
}
|
|
||||||
+35
-7
@@ -1,11 +1,38 @@
|
|||||||
using System;
|
//-----------------------------------------------------------------------
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// file="MatrixParallelThread.Fma"
|
||||||
|
// Project: StgSharp
|
||||||
|
// 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
|
||||||
|
// 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 StgSharp.HighPerformance;
|
||||||
|
using StgSharp.Internal;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using StgSharp.HighPerformance;
|
|
||||||
using StgSharp.Internal;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
@@ -13,10 +40,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
|
|
||||||
internal static unsafe void ComputeFmaPanelF32(
|
internal static unsafe void ComputeFmaPanelF32(
|
||||||
MatrixParallelTaskPackage* p
|
MatrixParallelTask* p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int f32 = (int)MatrixElementType.F32;
|
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||||
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
||||||
MatrixKernel* rightBuffer = (MatrixKernel*)p->Right;
|
MatrixKernel* rightBuffer = (MatrixKernel*)p->Right;
|
||||||
MatrixKernel* ansBuffer = (MatrixKernel*)p->Answer;
|
MatrixKernel* ansBuffer = (MatrixKernel*)p->Answer;
|
||||||
@@ -43,10 +70,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal static unsafe void ComputeFmaPanelF64(
|
internal static unsafe void ComputeFmaPanelF64(
|
||||||
MatrixParallelTaskPackage* p
|
MatrixParallelTask* p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int f64 = (int)MatrixElementType.F64;
|
int f64 = MatrixElementType.F64.IntrinsicNode;
|
||||||
|
|
||||||
// int size = 1;
|
// int size = 1;
|
||||||
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
||||||
@@ -73,5 +100,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
enumeration);
|
enumeration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -37,7 +37,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
private const int KernelStealCount = 64;
|
private const int KernelStealCount = 64;
|
||||||
|
|
||||||
internal unsafe void BufferCompute(
|
internal unsafe void BufferCompute(
|
||||||
MatrixParallelTaskPackage* p
|
MatrixParallelTask* p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// while () { }
|
// while () { }
|
||||||
@@ -55,7 +55,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe void SpecialBufferCompute(
|
internal unsafe void SpecialBufferCompute(
|
||||||
MatrixParallelTaskPackage* p
|
MatrixParallelTask* p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch ((MatrixElementType)p->ElementSize)
|
switch ((MatrixElementType)p->ElementSize)
|
||||||
+169
-169
@@ -1,169 +1,169 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallelThread"
|
// file="MatrixParallelThread"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Internal;
|
using StgSharp.Internal;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Mathematics.Internal;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
internal enum MatrixThreadState : int
|
internal enum MatrixThreadState : int
|
||||||
{
|
{
|
||||||
|
|
||||||
Born = 0,
|
Born = 0,
|
||||||
Ready = 1,
|
Ready = 1,
|
||||||
Running = 2,
|
Running = 2,
|
||||||
Idle = 4,
|
Idle = 4,
|
||||||
Retired = 8,
|
Retired = 8,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe partial class MatrixParallelThread : IDisposable
|
public unsafe partial class MatrixParallelThread : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
private IntPtr* _context;
|
private IntPtr* _context;
|
||||||
private volatile bool _disposed, _isRetireRequested = false;
|
private volatile bool _disposed, _isRetireRequested = false;
|
||||||
private readonly ManualResetEventSlim _resetEvent;
|
private readonly ManualResetEventSlim _resetEvent;
|
||||||
private readonly Thread _managedThread;
|
private readonly Thread _managedThread;
|
||||||
|
|
||||||
internal MatrixParallelThread(
|
internal MatrixParallelThread(
|
||||||
int poolId
|
int poolId
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_resetEvent = new ManualResetEventSlim(false);
|
_resetEvent = new ManualResetEventSlim(false);
|
||||||
_managedThread = new Thread(MatrixParallelWorkLoad);
|
_managedThread = new Thread(MatrixParallelWorkLoad);
|
||||||
_managedThread.Start();
|
_managedThread.Start();
|
||||||
PoolId = poolId;
|
PoolId = poolId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int PoolId { get; init; }
|
public int PoolId { get; init; }
|
||||||
|
|
||||||
public ThreadPriority AfterWork { get; set; }
|
public ThreadPriority AfterWork { get; set; }
|
||||||
|
|
||||||
internal ManualResetEventSlim? LeaderEvent { get; set; }
|
internal ManualResetEventSlim? LeaderEvent { get; set; }
|
||||||
|
|
||||||
internal IntrinsicContext* Intrinsic { get; set; }
|
internal IntrinsicContext* Intrinsic { get; set; }
|
||||||
|
|
||||||
internal bool IsSingle { get; set; }
|
internal bool IsSingle { get; set; }
|
||||||
|
|
||||||
internal MatrixParallelWrap BindedWrap { get; set; }
|
internal MatrixParallelWrap BindedWrap { get; set; }
|
||||||
|
|
||||||
internal MatrixThreadState State { get; set; }
|
internal MatrixThreadState State { get; set; }
|
||||||
|
|
||||||
internal SIMDID Simd { get; set; }
|
internal SIMDID Simd { get; set; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(disposing:true);
|
Dispose(disposing:true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
_resetEvent.Set();
|
_resetEvent.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "sn_get_simd_level_local")]
|
[LibraryImport(Native.LibName, EntryPoint = "sn_get_simd_level_local")]
|
||||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
internal static partial ulong GetSimdId();
|
internal static partial ulong GetSimdId();
|
||||||
|
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "sn_set_thread_affinity")]
|
[LibraryImport(Native.LibName, EntryPoint = "sn_set_thread_affinity")]
|
||||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
internal static partial void SetThreadAffinity(
|
internal static partial void SetThreadAffinity(
|
||||||
int coreId
|
int coreId
|
||||||
);
|
);
|
||||||
|
|
||||||
protected virtual void Dispose(
|
protected virtual void Dispose(
|
||||||
bool disposing
|
bool disposing
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!_disposed)
|
if (!_disposed)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_isRetireRequested = true;
|
_isRetireRequested = true;
|
||||||
_resetEvent.Set();
|
_resetEvent.Set();
|
||||||
_managedThread.Join();
|
_managedThread.Join();
|
||||||
_resetEvent.Dispose();
|
_resetEvent.Dispose();
|
||||||
}
|
}
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void MatrixParallelWorkLoad()
|
private unsafe void MatrixParallelWorkLoad()
|
||||||
{
|
{
|
||||||
State = MatrixThreadState.Born;
|
State = MatrixThreadState.Born;
|
||||||
|
|
||||||
// Bind OS-thread affinity once when the worker starts running
|
// Bind OS-thread affinity once when the worker starts running
|
||||||
SetThreadAffinity(PoolId);
|
SetThreadAffinity(PoolId);
|
||||||
Thread.Yield();
|
Thread.Yield();
|
||||||
SIMDID feature = new();
|
SIMDID feature = new();
|
||||||
feature.Mask = GetSimdId();
|
feature.Mask = GetSimdId();
|
||||||
_context = (nint*)MatrixParallel.GetContext(feature);
|
_context = (nint*)MatrixParallel.GetContext(feature);
|
||||||
State = MatrixThreadState.Ready;
|
State = MatrixThreadState.Ready;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Thread self = Thread.CurrentThread;
|
// Thread self = Thread.CurrentThread;
|
||||||
_resetEvent.Wait();
|
_resetEvent.Wait();
|
||||||
_resetEvent.Reset();
|
_resetEvent.Reset();
|
||||||
if (_isRetireRequested)
|
if (_isRetireRequested)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
State = MatrixThreadState.Running;
|
State = MatrixThreadState.Running;
|
||||||
AfterWork = BindedWrap.AfterWork;
|
AfterWork = BindedWrap.AfterWork;
|
||||||
_managedThread.Priority = ThreadPriority.Highest;
|
_managedThread.Priority = ThreadPriority.Highest;
|
||||||
if (IsSingle)
|
if (IsSingle)
|
||||||
{
|
{
|
||||||
// TODO 将外部线程绑定到当前线程上,并执行任务包
|
// TODO 将外部线程绑定到当前线程上,并执行任务包
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
MatrixParallelQueue taskQueue = BindedWrap.TaskQueue;
|
MatrixParallelQueue taskQueue = BindedWrap.TaskQueue;
|
||||||
MatrixParallelTaskPackage* p = taskQueue.Package;
|
MatrixParallelTask* p = taskQueue.Package;
|
||||||
if (0 > (int)p ->ComputeHandle) {
|
if (0 > (int)p ->ComputeHandle) {
|
||||||
SpecialBufferCompute(p);
|
SpecialBufferCompute(p);
|
||||||
}
|
}
|
||||||
switch (p->ComputeMode)
|
switch (p->ComputeMode)
|
||||||
{
|
{
|
||||||
case MatrixIndexStyle.BUFFER_INDEX:
|
case MatrixIndexStyle.BUFFER_INDEX:
|
||||||
BufferCompute(p);
|
BufferCompute(p);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BindedWrap.ReportThreadAccomplished();
|
BindedWrap.ReportThreadAccomplished();
|
||||||
}
|
}
|
||||||
_managedThread.Priority = AfterWork;
|
_managedThread.Priority = AfterWork;
|
||||||
State = MatrixThreadState.Idle;
|
State = MatrixThreadState.Idle;
|
||||||
}
|
}
|
||||||
State = MatrixThreadState.Retired;
|
State = MatrixThreadState.Retired;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+122
-122
@@ -1,122 +1,122 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallelWrap.cs"
|
// file="MatrixParallelWrap.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// obtaining a copy of this software and associated documentation
|
// obtaining a copy of this software and associated documentation
|
||||||
// files (the “Software”), to deal in the Software without restriction,
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// including without limitation the rights to use, copy, modify, merge,
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// and to permit persons to whom the Software is furnished to do so,
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
// subject to the following conditions:
|
// subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and
|
// The above copyright notice and
|
||||||
// this permission notice shall be included in all copies
|
// this permission notice shall be included in all copies
|
||||||
// or substantial portions of the Software.
|
// or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
// 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,
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Collections;
|
using StgSharp.Collections;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public enum SleepMode : int
|
public enum SleepMode : int
|
||||||
{
|
{
|
||||||
|
|
||||||
QuickWakeup = ThreadPriority.AboveNormal,
|
QuickWakeup = ThreadPriority.AboveNormal,
|
||||||
NormalSleep = ThreadPriority.BelowNormal,
|
NormalSleep = ThreadPriority.BelowNormal,
|
||||||
DeepSleep = ThreadPriority.Lowest,
|
DeepSleep = ThreadPriority.Lowest,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MatrixParallelWrap : IDisposable
|
public class MatrixParallelWrap : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
private MatrixParallelThread[] _threads;
|
private MatrixParallelThread[] _threads;
|
||||||
private bool _disposed = false;
|
private bool _disposed = false;
|
||||||
private int _count;
|
private int _count;
|
||||||
|
|
||||||
internal MatrixParallelWrap(MatrixParallelThread[] threadArray)
|
internal MatrixParallelWrap(MatrixParallelThread[] threadArray)
|
||||||
{
|
{
|
||||||
_threads = threadArray;
|
_threads = threadArray;
|
||||||
IsMultithread = threadArray.Length > 1;
|
IsMultithread = threadArray.Length > 1;
|
||||||
_count = threadArray.Length;
|
_count = threadArray.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MatrixParallelQueue TaskQueue { get; set; }
|
public MatrixParallelQueue TaskQueue { get; set; }
|
||||||
|
|
||||||
public ReadOnlySpan<MatrixParallelThread> Threads
|
public ReadOnlySpan<MatrixParallelThread> Threads
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_disposed) {
|
if (_disposed) {
|
||||||
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
||||||
}
|
}
|
||||||
return _threads;
|
return _threads;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThreadPriority AfterWork { get; private set; }
|
public ThreadPriority AfterWork { get; private set; }
|
||||||
|
|
||||||
private bool IsMultithread { get; init; }
|
private bool IsMultithread { get; init; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (_disposed) {
|
if (_disposed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixParallel.ReturnParallelResources(ref _threads);
|
MatrixParallel.ReturnParallelResources(ref _threads);
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void LaunchParallel(SleepMode afterWork)
|
public void LaunchParallel(SleepMode afterWork)
|
||||||
{
|
{
|
||||||
AfterWork = (ThreadPriority)afterWork;
|
AfterWork = (ThreadPriority)afterWork;
|
||||||
foreach (MatrixParallelThread thread in _threads)
|
foreach (MatrixParallelThread thread in _threads)
|
||||||
{
|
{
|
||||||
thread.AfterWork = AfterWork;
|
thread.AfterWork = AfterWork;
|
||||||
thread.BindedWrap = this;
|
thread.BindedWrap = this;
|
||||||
}
|
}
|
||||||
WaitAllWraps();
|
WaitAllWraps();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WaitAllWraps()
|
public void WaitAllWraps()
|
||||||
{
|
{
|
||||||
if (_disposed) {
|
if (_disposed) {
|
||||||
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
||||||
}
|
}
|
||||||
SpinWait.SpinUntil(() => Volatile.Read(ref _count) == 0);
|
SpinWait.SpinUntil(() => Volatile.Read(ref _count) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal void ReportThreadAccomplished()
|
internal void ReportThreadAccomplished()
|
||||||
{
|
{
|
||||||
if (_disposed) {
|
if (_disposed) {
|
||||||
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
throw new ObjectDisposedException(typeof(MatrixParallelWrap).Name);
|
||||||
}
|
}
|
||||||
Interlocked.Decrement(ref _count);
|
Interlocked.Decrement(ref _count);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+118
-118
@@ -1,119 +1,119 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixTaskFactory"
|
// file="MatrixTaskFactory"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.HighPerformance;
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using hlsfAllocator = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
using hlsfAllocator = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
internal static unsafe class MatrixParallelFactory
|
internal static unsafe class MatrixParallelFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
private static hlsfAllocator _intermediateResult;
|
private static hlsfAllocator _intermediateResult;
|
||||||
|
|
||||||
private static
|
private static
|
||||||
#if NET9_0_OR_GREATER
|
#if NET9_0_OR_GREATER
|
||||||
Lock
|
Lock
|
||||||
#else
|
#else
|
||||||
object
|
object
|
||||||
#endif
|
#endif
|
||||||
_hlsfLock = new();
|
_hlsfLock = new();
|
||||||
|
|
||||||
private static SlabAllocator<ScalarPacket> _scalarAllocator ;
|
private static SlabAllocator<ScalarPacket> _scalarAllocator ;
|
||||||
|
|
||||||
private static SlabAllocator<MatrixParallelTaskPackage> _wrapAllocator;
|
private static SlabAllocator<MatrixParallelTask> _wrapAllocator;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static MatrixParallelTaskPackage* CreateBaseTask()
|
public static MatrixParallelTask* CreateBaseTask()
|
||||||
{
|
{
|
||||||
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
|
MatrixParallelTask* p = (MatrixParallelTask*)_wrapAllocator.Allocate();
|
||||||
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTaskPackage));
|
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTask));
|
||||||
s.Fill(0);
|
s.Fill(0);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ScalarPacket* CreateScalarPacket()
|
public static ScalarPacket* CreateScalarPacket()
|
||||||
{
|
{
|
||||||
ScalarPacket* p = (ScalarPacket*)_scalarAllocator.Allocate();
|
ScalarPacket* p = (ScalarPacket*)_scalarAllocator.Allocate();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe MatrixParallelTaskPackage* FromExistPackage(
|
public static unsafe MatrixParallelTask* FromExistPackage(
|
||||||
MatrixParallelTaskPackage* exist
|
MatrixParallelTask* exist
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
MatrixParallelTaskPackage* ptr = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
|
MatrixParallelTask* ptr = (MatrixParallelTask*)_wrapAllocator.Allocate();
|
||||||
MatrixParallelTaskPackage.Copy(exist, ptr);
|
MatrixParallelTask.Copy(exist, ptr);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
||||||
public static void Release(
|
public static void Release(
|
||||||
ScalarPacket* source
|
ScalarPacket* source
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_scalarAllocator.Free((nuint)source);
|
_scalarAllocator.Free((nuint)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Release(
|
public static void Release(
|
||||||
MatrixParallelTaskPackage* source
|
MatrixParallelTask* source
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (source->Scalar != null) {
|
if (source->Scalar != null) {
|
||||||
_scalarAllocator.Free((nuint)source->Scalar);
|
_scalarAllocator.Free((nuint)source->Scalar);
|
||||||
}
|
}
|
||||||
_wrapAllocator.Free((nuint)source);
|
_wrapAllocator.Free((nuint)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static void Init()
|
internal static void Init()
|
||||||
{
|
{
|
||||||
if (_intermediateResult is null)
|
if (_intermediateResult is null)
|
||||||
{
|
{
|
||||||
_intermediateResult = new hlsfAllocator(64 * 16 * 16);
|
_intermediateResult = new hlsfAllocator(64 * 16 * 16);
|
||||||
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64 * 1024, SlabBufferLayout.Chunked);
|
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64 * 1024, SlabBufferLayout.Chunked);
|
||||||
_wrapAllocator = SlabAllocator<MatrixParallelTaskPackage>.
|
_wrapAllocator = SlabAllocator<MatrixParallelTask>.
|
||||||
Create(128 * 1024, SlabBufferLayout.Chunked);
|
Create(128 * 1024, SlabBufferLayout.Chunked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+107
-107
@@ -1,107 +1,107 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ACos"
|
// file="ACos"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe float ACos(float x)
|
public static unsafe float ACos(float x)
|
||||||
{
|
{
|
||||||
return MathF.Acos(x);
|
return MathF.Acos(x);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
y = -x;
|
y = -x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
y = x;
|
y = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x > 1)
|
if (x > 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
float r, s, u, vec = 0.0f;
|
float r, s, u, vec = 0.0f;
|
||||||
bool transform = (y >= 0.5f);
|
bool transform = (y >= 0.5f);
|
||||||
|
|
||||||
if (transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
r = 0.5f * (1.0f - y);
|
r = 0.5f * (1.0f - y);
|
||||||
s = Scaler.Sqrt(r);
|
s = Scaler.Sqrt(r);
|
||||||
y = s;
|
y = s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = y * y;
|
r = y * y;
|
||||||
}
|
}
|
||||||
u = r * (0.184161606965100694821398249421F +
|
u = r * (0.184161606965100694821398249421F +
|
||||||
(-0.0565298683201845211985026327361F +
|
(-0.0565298683201845211985026327361F +
|
||||||
(-0.0133819288943925804214011424456F -
|
(-0.0133819288943925804214011424456F -
|
||||||
0.00396137437848476485201154797087F * r) * r) * r) /
|
0.00396137437848476485201154797087F * r) * r) * r) /
|
||||||
(1.10496961524520294485512696706F -
|
(1.10496961524520294485512696706F -
|
||||||
0.836411276854206731913362287293F * r);
|
0.836411276854206731913362287293F * r);
|
||||||
/*
|
/*
|
||||||
|
|
||||||
if (transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
float c, s1, p, q;
|
float c, s1, p, q;
|
||||||
uint us;
|
uint us;
|
||||||
|
|
||||||
us = *(uint*)&s;
|
us = *(uint*)&s;
|
||||||
uint uss = us & 0xffff0000;
|
uint uss = us & 0xffff0000;
|
||||||
s1 = *(float*)&uss;
|
s1 = *(float*)&uss;
|
||||||
|
|
||||||
c = (r - s1 * s1) / (s + s1);
|
c = (r - s1 * s1) / (s + s1);
|
||||||
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
||||||
q = hpiby2_head - 2.0F * s1;
|
q = hpiby2_head - 2.0F * s1;
|
||||||
vec = hpiby2_head - (p - q);
|
vec = hpiby2_head - (p - q);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vec = y + y * u;
|
vec = y + y * u;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec = sign * vec;
|
vec = sign * vec;
|
||||||
|
|
||||||
return piby2 - vec;
|
return piby2 - vec;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+119
-119
@@ -1,119 +1,119 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ASin"
|
// file="ASin"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
private const float
|
private const float
|
||||||
piby2_tail = 7.5497894159e-08f, /* 0x33a22168 */
|
piby2_tail = 7.5497894159e-08f, /* 0x33a22168 */
|
||||||
hpiby2_head = 7.8539812565e-01f, /* 0x3f490fda */
|
hpiby2_head = 7.8539812565e-01f, /* 0x3f490fda */
|
||||||
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
|
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reurns the value of ArcSin(x)
|
/// Reurns the value of ArcSin(x)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="x">
|
/// <param _label="x">
|
||||||
/// The sine value of the angle
|
/// The sine value of the angle
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
///
|
///
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static float ASin(float x)
|
public static float ASin(float x)
|
||||||
{
|
{
|
||||||
return MathF.Asin(x);
|
return MathF.Asin(x);
|
||||||
/*
|
/*
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
y = -x;
|
y = -x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
y = x;
|
y = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x > 1)
|
if (x > 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
float r, s, u, vec = 0.0f;
|
float r, s, u, vec = 0.0f;
|
||||||
bool transform = (y >= 0.5f);
|
bool transform = (y >= 0.5f);
|
||||||
|
|
||||||
if (transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
r = 0.5f * (1.0f - y);
|
r = 0.5f * (1.0f - y);
|
||||||
s = Scaler.Sqrt(r);
|
s = Scaler.Sqrt(r);
|
||||||
y = s;
|
y = s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = y * y;
|
r = y * y;
|
||||||
}
|
}
|
||||||
u = r * (0.184161606965100694821398249421F +
|
u = r * (0.184161606965100694821398249421F +
|
||||||
(-0.0565298683201845211985026327361F +
|
(-0.0565298683201845211985026327361F +
|
||||||
(-0.0133819288943925804214011424456F -
|
(-0.0133819288943925804214011424456F -
|
||||||
0.00396137437848476485201154797087F * r) * r) * r) /
|
0.00396137437848476485201154797087F * r) * r) * r) /
|
||||||
(1.10496961524520294485512696706F -
|
(1.10496961524520294485512696706F -
|
||||||
0.836411276854206731913362287293F * r);
|
0.836411276854206731913362287293F * r);
|
||||||
/*
|
/*
|
||||||
|
|
||||||
if (transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
float c, s1, p, q;
|
float c, s1, p, q;
|
||||||
uint us;
|
uint us;
|
||||||
|
|
||||||
us = *(uint*)&s;
|
us = *(uint*)&s;
|
||||||
uint uss = us & 0xffff0000;
|
uint uss = us & 0xffff0000;
|
||||||
s1 = *(float*)&uss;
|
s1 = *(float*)&uss;
|
||||||
|
|
||||||
c = (r - s1 * s1) / (s + s1);
|
c = (r - s1 * s1) / (s + s1);
|
||||||
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
||||||
q = hpiby2_head - 2.0F * s1;
|
q = hpiby2_head - 2.0F * s1;
|
||||||
vec = hpiby2_head - (p - q);
|
vec = hpiby2_head - (p - q);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vec = y + y * u;
|
vec = y + y * u;
|
||||||
}/*
|
}/*
|
||||||
|
|
||||||
return sign * vec;
|
return sign * vec;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+116
-116
@@ -1,116 +1,116 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ATan"
|
// file="ATan"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe float ATan(float x)
|
public static unsafe float ATan(float x)
|
||||||
{
|
{
|
||||||
return MathF.Atan(x);
|
return MathF.Atan(x);
|
||||||
/*
|
/*
|
||||||
float sign = 1, angle = 0;
|
float sign = 1, angle = 0;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
x = -x;
|
x = -x;
|
||||||
}
|
}
|
||||||
uint xBit = *(uint*)&x;
|
uint xBit = *(uint*)&x;
|
||||||
int xExp = (int)(xBit >> 23) - 127;
|
int xExp = (int)(xBit >> 23) - 127;
|
||||||
if (xExp >= 26)
|
if (xExp >= 26)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (xExp <= -15)
|
if (xExp <= -15)
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
if (xExp >= 0)
|
if (xExp >= 0)
|
||||||
{
|
{
|
||||||
x = (x - 1) / (x + 1);
|
x = (x - 1) / (x + 1);
|
||||||
angle = 0.7853981634f;
|
angle = 0.7853981634f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float vec = 0.7853981634f * x + x * (1 - x) * (0.2447f + 0.0663f * x);
|
float vec = 0.7853981634f * x + x * (1 - x) * (0.2447f + 0.0663f * x);
|
||||||
vec += angle;
|
vec += angle;
|
||||||
vec *= sign;
|
vec *= sign;
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static unsafe float ATan(float x, float y)
|
public static unsafe float ATan(float x, float y)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
float z = y / x;
|
float z = y / x;
|
||||||
|
|
||||||
float sign = 1, angle = 0, angle2 = 0;
|
float sign = 1, angle = 0, angle2 = 0;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
angle = -3.1415926535f;
|
angle = -3.1415926535f;
|
||||||
}
|
}
|
||||||
if (z < 0)
|
if (z < 0)
|
||||||
{
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
z = -z;
|
z = -z;
|
||||||
}
|
}
|
||||||
uint zBit = *(uint*)&z;
|
uint zBit = *(uint*)&z;
|
||||||
int zExp = (int)(zBit >> 23) - 127;
|
int zExp = (int)(zBit >> 23) - 127;
|
||||||
if (zExp >= 26)
|
if (zExp >= 26)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (zExp <= -15)
|
if (zExp <= -15)
|
||||||
{
|
{
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
if (zExp >= 0)
|
if (zExp >= 0)
|
||||||
{
|
{
|
||||||
z = (z - 1) / (z + 1);
|
z = (z - 1) / (z + 1);
|
||||||
angle2 = 0.7853981634f;
|
angle2 = 0.7853981634f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float vec = 0.7853981634f * z + z * (1 - z) * (0.2447f + 0.0663f * z);
|
float vec = 0.7853981634f * z + z * (1 - z) * (0.2447f + 0.0663f * z);
|
||||||
vec *= 57.29577951f;
|
vec *= 57.29577951f;
|
||||||
vec += angle2;
|
vec += angle2;
|
||||||
vec += angle;
|
vec += angle;
|
||||||
vec *= sign;
|
vec *= sign;
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+66
-66
@@ -1,67 +1,67 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="BasicOps"
|
// file="BasicOps"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe float Abs(float x)
|
public static unsafe float Abs(float x)
|
||||||
{
|
{
|
||||||
uint* a = (uint*)&x;
|
uint* a = (uint*)&x;
|
||||||
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||||
return *(float*)a;
|
return *(float*)a;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int Abs(int x)
|
public static unsafe int Abs(int x)
|
||||||
{
|
{
|
||||||
uint* a = (uint*)&x;
|
uint* a = (uint*)&x;
|
||||||
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||||
return *(int*)a;
|
return *(int*)a;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetListSeparator(IFormatProvider formatProvider)
|
internal static string GetListSeparator(IFormatProvider formatProvider)
|
||||||
{
|
{
|
||||||
if (formatProvider is CultureInfo cultureInfo) {
|
if (formatProvider is CultureInfo cultureInfo) {
|
||||||
return cultureInfo.TextInfo.ListSeparator;
|
return cultureInfo.TextInfo.ListSeparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formatProvider?.GetFormat(typeof(TextInfo)) is TextInfo textInfo) {
|
if (formatProvider?.GetFormat(typeof(TextInfo)) is TextInfo textInfo) {
|
||||||
return textInfo.ListSeparator;
|
return textInfo.ListSeparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+64
-64
@@ -1,64 +1,64 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Compare"
|
// file="Compare"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static partial class Scalar
|
public static partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float MaxOf(params float[] stream)
|
public static float MaxOf(params float[] stream)
|
||||||
{
|
{
|
||||||
float ret = stream[0];
|
float ret = stream[0];
|
||||||
foreach (float num in stream)
|
foreach (float num in stream)
|
||||||
{
|
{
|
||||||
if (ret < num) {
|
if (ret < num) {
|
||||||
ret = num;
|
ret = num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float MinOf(params float[] stream)
|
public static float MinOf(params float[] stream)
|
||||||
{
|
{
|
||||||
float ret = stream[0];
|
float ret = stream[0];
|
||||||
foreach (float num in stream)
|
foreach (float num in stream)
|
||||||
{
|
{
|
||||||
if (ret > num) {
|
if (ret > num) {
|
||||||
ret = num;
|
ret = num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+57
-57
@@ -1,57 +1,57 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Cos"
|
// file="Cos"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static partial class Scalar
|
public static partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Cos(float x)
|
public static float Cos(float x)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
float refer = x / 360.0f;
|
float refer = x / 360.0f;
|
||||||
refer -= (int)refer;
|
refer -= (int)refer;
|
||||||
|
|
||||||
refer *= 40;
|
refer *= 40;
|
||||||
int a = (int)refer; //大分度,查表
|
int a = (int)refer; //大分度,查表
|
||||||
refer -= a; //小分度,拟合
|
refer -= a; //小分度,拟合
|
||||||
|
|
||||||
float refer2 = refer * refer;
|
float refer2 = refer * refer;
|
||||||
|
|
||||||
|
|
||||||
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
|
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
|
||||||
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
|
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
|
||||||
*/
|
*/
|
||||||
return MathF.Cos(x);
|
return MathF.Cos(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+52
-52
@@ -1,52 +1,52 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Ctor"
|
// file="Ctor"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public unsafe delegate float ScalarCalcHandler(float* x);
|
public unsafe delegate float ScalarCalcHandler(float* x);
|
||||||
|
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
private const uint MEM_COMMIT = 0x1000;
|
private const uint MEM_COMMIT = 0x1000;
|
||||||
private const uint MEM_RELEASE = 0x8000;
|
private const uint MEM_RELEASE = 0x8000;
|
||||||
private const uint MEM_RESERVE = 0x2000;
|
private const uint MEM_RESERVE = 0x2000;
|
||||||
private const uint PAGE_EXECUTE_READWRITE = 0x40;
|
private const uint PAGE_EXECUTE_READWRITE = 0x40;
|
||||||
|
|
||||||
static Scalar() { }
|
static Scalar() { }
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
|
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
|
||||||
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
|
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
|
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
|
||||||
private static extern bool VirtualFree(IntPtr address, int size, uint freeType);
|
private static extern bool VirtualFree(IntPtr address, int size, uint freeType);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+109
-109
@@ -1,109 +1,109 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Exp"
|
// file="Exp"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
public const float E = 2.718281828f;
|
public const float E = 2.718281828f;
|
||||||
public const double EDouble = System.Math.E;
|
public const double EDouble = System.Math.E;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Exp(float x)
|
public static float Exp(float x)
|
||||||
{
|
{
|
||||||
return MathF.Exp(x);
|
return MathF.Exp(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static double Exp(double x)
|
public static double Exp(double x)
|
||||||
{
|
{
|
||||||
return System.Math.Exp(x);
|
return System.Math.Exp(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the value of E ^ x;
|
/// Get the value of E ^ x;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="x">
|
/// <param _label="x">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static unsafe float ExpSlow(float x)
|
public static unsafe float ExpSlow(float x)
|
||||||
{
|
{
|
||||||
if (x == 1) {
|
if (x == 1) {
|
||||||
return E;
|
return E;
|
||||||
}
|
}
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
sign = true;
|
sign = true;
|
||||||
x = -x;
|
x = -x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float z = x, t;
|
float z = x, t;
|
||||||
if (x < 0.5f)
|
if (x < 0.5f)
|
||||||
{
|
{
|
||||||
t = 1.0f + (x * (1.0f + (x * (0.5f + (x * (0.1666666667f + (x * (0.0416666666667f + (x * 8.333333333e-3f)))))))));
|
t = 1.0f + (x * (1.0f + (x * (0.5f + (x * (0.1666666667f + (x * (0.0416666666667f + (x * 8.333333333e-3f)))))))));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* define z = n * 2 ^ m
|
* define z = n * 2 ^ m
|
||||||
* n is between 0 and 0.5
|
* n is between 0 and 0.5
|
||||||
*/
|
*/
|
||||||
uint zBit = *(uint*)&z;
|
uint zBit = *(uint*)&z;
|
||||||
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||||
uint uintm = zBitAbs >> 23;
|
uint uintm = zBitAbs >> 23;
|
||||||
int m = (*(int*)&uintm) - 126;
|
int m = (*(int*)&uintm) - 126;
|
||||||
|
|
||||||
|
|
||||||
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
||||||
float n = (*(float*)&nBit) - 1;
|
float n = (*(float*)&nBit) - 1;
|
||||||
|
|
||||||
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) {
|
for (int i = 0; i < m; i++) {
|
||||||
t = t * t;
|
t = t * t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
t = 1 / t;
|
t = 1 / t;
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+68
-68
@@ -1,68 +1,68 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Factorial"
|
// file="Factorial"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static partial class Scalar
|
public static partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly uint[] factorialResult = [
|
private static readonly uint[] factorialResult = [
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
6,
|
6,
|
||||||
24,
|
24,
|
||||||
120,
|
120,
|
||||||
720,
|
720,
|
||||||
5040,
|
5040,
|
||||||
40320,
|
40320,
|
||||||
362880,
|
362880,
|
||||||
3628800,
|
3628800,
|
||||||
39916800,
|
39916800,
|
||||||
479001600
|
479001600
|
||||||
];
|
];
|
||||||
|
|
||||||
public static unsafe ulong Factorial(int n)
|
public static unsafe ulong Factorial(int n)
|
||||||
{
|
{
|
||||||
ArgumentOutOfRangeException.ThrowIfLessThan(n, 0);
|
ArgumentOutOfRangeException.ThrowIfLessThan(n, 0);
|
||||||
if (n < 13) {
|
if (n < 13) {
|
||||||
return factorialResult[n];
|
return factorialResult[n];
|
||||||
}
|
}
|
||||||
if (n < 30) {
|
if (n < 30) {
|
||||||
return NativeIntrinsic.Context.factorial_simd(n);
|
return NativeIntrinsic.Context.factorial_simd(n);
|
||||||
}
|
}
|
||||||
double
|
double
|
||||||
dn = n,
|
dn = n,
|
||||||
stir = Sqrt(2 * PiDouble * dn) * Pow(dn / EDouble, dn),
|
stir = Sqrt(2 * PiDouble * dn) * Pow(dn / EDouble, dn),
|
||||||
correction = Exp(1 / (12 * dn));
|
correction = Exp(1 / (12 * dn));
|
||||||
return (ulong)(stir * correction);
|
return (ulong)(stir * correction);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+31
-31
@@ -1,31 +1,31 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Function"
|
// file="Function"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public class Function { }
|
public class Function { }
|
||||||
}
|
}
|
||||||
+80
-80
@@ -1,80 +1,80 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Log"
|
// file="Log"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static partial class Scalar
|
public static partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly float[] logArray = {
|
private static readonly float[] logArray = {
|
||||||
0f, 0.00995033085316809f, 0.0198026272961797f, 0.0295588022415444f, 0.0392207131532813f, 0.048790164169432f, 0.0582689081239758f, 0.0676586484738149f, 0.0769610411361284f, 0.0861776962410524f, 0.0953101798043249f, 0.104360015324243f, 0.113328685307003f, 0.122217632724249f, 0.131028262406404f, 0.139761942375159f, 0.148420005118273f, 0.157003748809665f, 0.165514438477573f, 0.173953307123438f, 0.182321556793955f, 0.19062035960865f, 0.198850858745165f, 0.207014169384326f, 0.215111379616945f, 0.22314355131421f, 0.231111720963387f, 0.2390169004705f, 0.246860077931526f, 0.254642218373581f, 0.262364264467491f, 0.27002713721306f, 0.27763173659828f, 0.285178942233662f, 0.29266961396282f, 0.300104592450338f, 0.307484699747961f, 0.314810739840034f, 0.322083499169113f, 0.3293037471426f, 0.336472236621213f, 0.343589704390077f, 0.350656871613169f, 0.357674444271816f, 0.364643113587909f, 0.371563556432483f, 0.378436435720245f, 0.385262400790645f, 0.392042087776024f, 0.398776119957368f, 0.405465108108164f, 0.412109650826833f, 0.418710334858185f, 0.425267735404344f, 0.431782416425538f, 0.438254930931155f, 0.444685821261446f, 0.451075619360217f, 0.457424847038875f, 0.46373401623214f, 0.470003629245736f, 0.476234178996372f, 0.482426149244293f, 0.488580014818671f, 0.494696241836107f, 0.500775287912489f, 0.506817602368452f, 0.512823626428664f, 0.518793793415168f, 0.524728528934982f, 0.53062825106217f, 0.536493370514568f, 0.542324290825362f, 0.548121408509688f, 0.553885113226438f, 0.559615787935423f, 0.56531380905006f, 0.570979546585738f, 0.576613364303994f, 0.582215619852664f, 0.587786664902119f, 0.593326845277734f, 0.598836501088704f, 0.60431596685333f, 0.609765571620894f, 0.615185639090233f, 0.62057648772511f, 0.625938430866495f, 0.631271776841858f, 0.636576829071551f, 0.641853886172395f, 0.647103242058538f, 0.65232518603969f, 0.657520002916794f, 0.662687973075237f, 0.667829372575655f, 0.672944473242426f, 0.678033542749897f, 0.683096844706444f, 0.688134638736401f,
|
0f, 0.00995033085316809f, 0.0198026272961797f, 0.0295588022415444f, 0.0392207131532813f, 0.048790164169432f, 0.0582689081239758f, 0.0676586484738149f, 0.0769610411361284f, 0.0861776962410524f, 0.0953101798043249f, 0.104360015324243f, 0.113328685307003f, 0.122217632724249f, 0.131028262406404f, 0.139761942375159f, 0.148420005118273f, 0.157003748809665f, 0.165514438477573f, 0.173953307123438f, 0.182321556793955f, 0.19062035960865f, 0.198850858745165f, 0.207014169384326f, 0.215111379616945f, 0.22314355131421f, 0.231111720963387f, 0.2390169004705f, 0.246860077931526f, 0.254642218373581f, 0.262364264467491f, 0.27002713721306f, 0.27763173659828f, 0.285178942233662f, 0.29266961396282f, 0.300104592450338f, 0.307484699747961f, 0.314810739840034f, 0.322083499169113f, 0.3293037471426f, 0.336472236621213f, 0.343589704390077f, 0.350656871613169f, 0.357674444271816f, 0.364643113587909f, 0.371563556432483f, 0.378436435720245f, 0.385262400790645f, 0.392042087776024f, 0.398776119957368f, 0.405465108108164f, 0.412109650826833f, 0.418710334858185f, 0.425267735404344f, 0.431782416425538f, 0.438254930931155f, 0.444685821261446f, 0.451075619360217f, 0.457424847038875f, 0.46373401623214f, 0.470003629245736f, 0.476234178996372f, 0.482426149244293f, 0.488580014818671f, 0.494696241836107f, 0.500775287912489f, 0.506817602368452f, 0.512823626428664f, 0.518793793415168f, 0.524728528934982f, 0.53062825106217f, 0.536493370514568f, 0.542324290825362f, 0.548121408509688f, 0.553885113226438f, 0.559615787935423f, 0.56531380905006f, 0.570979546585738f, 0.576613364303994f, 0.582215619852664f, 0.587786664902119f, 0.593326845277734f, 0.598836501088704f, 0.60431596685333f, 0.609765571620894f, 0.615185639090233f, 0.62057648772511f, 0.625938430866495f, 0.631271776841858f, 0.636576829071551f, 0.641853886172395f, 0.647103242058538f, 0.65232518603969f, 0.657520002916794f, 0.662687973075237f, 0.667829372575655f, 0.672944473242426f, 0.678033542749897f, 0.683096844706444f, 0.688134638736401f,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="x">
|
/// <param _label="x">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// Returns the value of ln(x).
|
/// Returns the value of ln(x).
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static unsafe float Log(float x)
|
public static unsafe float Log(float x)
|
||||||
{
|
{
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
uint input = *(uint*)&x;
|
uint input = *(uint*)&x;
|
||||||
|
|
||||||
int f = (int)input;
|
int f = (int)input;
|
||||||
f >>= 23;
|
f >>= 23;
|
||||||
f -= 127;
|
f -= 127;
|
||||||
input <<= 9;
|
input <<= 9;
|
||||||
input >>= 9;
|
input >>= 9;
|
||||||
input += 0b_0011_1111_1000_0000_0000_0000_0000_0000;
|
input += 0b_0011_1111_1000_0000_0000_0000_0000_0000;
|
||||||
float result = *(float*)&input;
|
float result = *(float*)&input;
|
||||||
uint order = ((uint)(result * 100)) - 100;
|
uint order = ((uint)(result * 100)) - 100;
|
||||||
|
|
||||||
float cache = (result / (1f + (0.01f * order))) - 1;
|
float cache = (result / (1f + (0.01f * order))) - 1;
|
||||||
result = (cache * (-0.25f)) + 0.3333333333333f;
|
result = (cache * (-0.25f)) + 0.3333333333333f;
|
||||||
result = (result * cache) - 0.5f;
|
result = (result * cache) - 0.5f;
|
||||||
result = (result * cache) + 1.0f;
|
result = (result * cache) + 1.0f;
|
||||||
result *= cache;
|
result *= cache;
|
||||||
|
|
||||||
return
|
return
|
||||||
(f * 0.6931471806f) + result + logArray[order];
|
(f * 0.6931471806f) + result + logArray[order];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float Log(float x, float y)
|
public static float Log(float x, float y)
|
||||||
{
|
{
|
||||||
return Log(x) / Log(y);
|
return Log(x) / Log(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+121
-121
@@ -1,121 +1,121 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Pow"
|
// file="Pow"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe float Pow(float x, float y)
|
public static unsafe float Pow(float x, float y)
|
||||||
{
|
{
|
||||||
return System.MathF.Pow(x, y);
|
return System.MathF.Pow(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe double Pow(double x, double y)
|
public static unsafe double Pow(double x, double y)
|
||||||
{
|
{
|
||||||
return System.Math.Pow(x, y);
|
return System.Math.Pow(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// calculate the value of x^y
|
/// calculate the value of x^y
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="x">
|
/// <param _label="x">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param _label="y">
|
/// <param _label="y">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// Returns the value of x^y
|
/// Returns the value of x^y
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static unsafe float PowSlow(float x, float y)
|
public static unsafe float PowSlow(float x, float y)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* x^y = E ^ ( log( x ) * y )
|
* x^y = E ^ ( log( x ) * y )
|
||||||
* Now define z = | log(x) * y | = m * n
|
* Now define z = | log(x) * y | = m * n
|
||||||
* and m is an integer, and 0.5 < |n| < 1
|
* and m is an integer, and 0.5 < |n| < 1
|
||||||
* then E ^ z = ( E ^ n ) ^ m
|
* then E ^ z = ( E ^ n ) ^ m
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* As a float number can be expressed in (1+e)*(2^f)
|
* As a float number can be expressed in (1+e)*(2^f)
|
||||||
* n = (1+e)/2
|
* n = (1+e)/2
|
||||||
* m = 2 ^ (f + 1)
|
* m = 2 ^ (f + 1)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
float z, t;
|
float z, t;
|
||||||
if ((x == 1) || (y == 0)) {
|
if ((x == 1) || (y == 0)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((x == 1) && (y == 0)) {
|
if ((x == 1) && (y == 0)) {
|
||||||
return float.PositiveInfinity;
|
return float.PositiveInfinity;
|
||||||
}
|
}
|
||||||
if ((x == 0) && (y != 0)) {
|
if ((x == 0) && (y != 0)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
z = Scalar.Log(x) * y;
|
z = Scalar.Log(x) * y;
|
||||||
|
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
if (z < 0)
|
if (z < 0)
|
||||||
{
|
{
|
||||||
sign = true;
|
sign = true;
|
||||||
z = -z;
|
z = -z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z < 0.5f)
|
if (z < 0.5f)
|
||||||
{
|
{
|
||||||
t = 1.0f + (z * (1.0f + (z * (0.5f + (z * (0.1666666667f + (z * (0.0416666666667f + (z * 8.333333333e-3f)))))))));
|
t = 1.0f + (z * (1.0f + (z * (0.5f + (z * (0.1666666667f + (z * (0.0416666666667f + (z * 8.333333333e-3f)))))))));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
uint zBit = *(uint*)&z;
|
uint zBit = *(uint*)&z;
|
||||||
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||||
uint uintm = zBitAbs >> 23;
|
uint uintm = zBitAbs >> 23;
|
||||||
int m = (*(int*)&uintm) - 126;
|
int m = (*(int*)&uintm) - 126;
|
||||||
|
|
||||||
|
|
||||||
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
||||||
float n = (*(float*)&nBit) - 1;
|
float n = (*(float*)&nBit) - 1;
|
||||||
|
|
||||||
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) {
|
for (int i = 0; i < m; i++) {
|
||||||
t = t * t;
|
t = t * t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sign) {
|
if (sign) {
|
||||||
t = 1 / t;
|
t = 1 / t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+126
-126
@@ -1,126 +1,126 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Random"
|
// file="Random"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
private static byte[] randomSeed;
|
private static byte[] randomSeed;
|
||||||
|
|
||||||
internal static float currentSeed
|
internal static float currentSeed
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
= 0.5f;
|
= 0.5f;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
= Abs(System.DateTime.UtcNow.GetHashCode());
|
= Abs(System.DateTime.UtcNow.GetHashCode());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// returns a random float number between 0 and 1.
|
/// returns a random float number between 0 and 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static unsafe float LowProceisionRandom()
|
public static unsafe float LowProceisionRandom()
|
||||||
{
|
{
|
||||||
float seed = currentSeed;
|
float seed = currentSeed;
|
||||||
|
|
||||||
float sample = Scalar.Pow(Scalar.SeedSqrt(seed), 2);
|
float sample = Scalar.Pow(Scalar.SeedSqrt(seed), 2);
|
||||||
float sample2 = (sample - seed) / seed;
|
float sample2 = (sample - seed) / seed;
|
||||||
sample2 = Scalar.Abs(sample2);
|
sample2 = Scalar.Abs(sample2);
|
||||||
|
|
||||||
if (sample == 1) {
|
if (sample == 1) {
|
||||||
sample = sample2;
|
sample = sample2;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSeed = sample;
|
currentSeed = sample;
|
||||||
sample2 *= 1000000;
|
sample2 *= 1000000;
|
||||||
|
|
||||||
float result = sample2 - ((int)sample2);
|
float result = sample2 - ((int)sample2);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
currentSeed = sample2 + 0.1f;
|
currentSeed = sample2 + 0.1f;
|
||||||
result = Scalar.LowProceisionRandom();
|
result = Scalar.LowProceisionRandom();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static T Random<T>() where T : unmanaged, IConvertible, INumber<T>
|
public static T Random<T>() where T : unmanaged, IConvertible, INumber<T>
|
||||||
|
|
||||||
{
|
{
|
||||||
if (randomSeed == null)
|
if (randomSeed == null)
|
||||||
{
|
{
|
||||||
randomSeed = new byte[64];
|
randomSeed = new byte[64];
|
||||||
string originSeed =
|
string originSeed =
|
||||||
($"{((Assembly.GetEntryAssembly() == null) ? (Assembly.GetAssembly(typeof(World))!) :
|
($"{((Assembly.GetEntryAssembly() == null) ? (Assembly.GetAssembly(typeof(World))!) :
|
||||||
Assembly.GetEntryAssembly())}") + ($"{DateTime.UtcNow.ToString("o")}");
|
Assembly.GetEntryAssembly())}") + ($"{DateTime.UtcNow.ToString("o")}");
|
||||||
randomSeed = SHA256.HashData(Encoding.UTF8.GetBytes(originSeed));
|
randomSeed = SHA256.HashData(Encoding.UTF8.GetBytes(originSeed));
|
||||||
}
|
}
|
||||||
randomSeed = SHA256.HashData(randomSeed);
|
randomSeed = SHA256.HashData(randomSeed);
|
||||||
fixed (byte* bptr = randomSeed) {
|
fixed (byte* bptr = randomSeed) {
|
||||||
return *(T*)bptr;
|
return *(T*)bptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a random seed in int value.
|
/// Generates a random seed in int value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///
|
///
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static unsafe int RandomSeed()
|
public static unsafe int RandomSeed()
|
||||||
{
|
{
|
||||||
float seedValue1 = LowProceisionRandom();
|
float seedValue1 = LowProceisionRandom();
|
||||||
float seedValue2 = LowProceisionRandom();
|
float seedValue2 = LowProceisionRandom();
|
||||||
uint seedValueBits = *(uint*)&seedValue1;
|
uint seedValueBits = *(uint*)&seedValue1;
|
||||||
|
|
||||||
float seedValue = seedValueBits * seedValue2;
|
float seedValue = seedValueBits * seedValue2;
|
||||||
|
|
||||||
return *(int*)&seedValue;
|
return *(int*)&seedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+65
-65
@@ -1,65 +1,65 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="SignOf"
|
// file="SignOf"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static unsafe partial class Scalar
|
public static unsafe partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int SignOf(float x)
|
public static unsafe int SignOf(float x)
|
||||||
{
|
{
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int SignOf(int x)
|
public static unsafe int SignOf(int x)
|
||||||
{
|
{
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+47
-47
@@ -1,47 +1,47 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Sin"
|
// file="Sin"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
public static partial class Scalar
|
public static partial class Scalar
|
||||||
{
|
{
|
||||||
|
|
||||||
public const float Pi = 3.1415926f;
|
public const float Pi = 3.1415926f;
|
||||||
public const double PiDouble = System.Math.PI;
|
public const double PiDouble = System.Math.PI;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe float Sin(float x)
|
public static unsafe float Sin(float x)
|
||||||
{
|
{
|
||||||
return MathF.Sin(x);
|
return MathF.Sin(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user