OpenGL rebuild project start!

This commit is contained in:
Nitload
2023-04-29 03:06:32 +08:00
parent 7dba067146
commit 4dd3f4f6d1
263 changed files with 51374 additions and 1522 deletions
+28 -87
View File
@@ -1,112 +1,53 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using static StgSharp.Optimization.CpuInfo;
namespace StgSharp.Optimization
{
public static unsafe partial class SSE
{
public static m128 sqrtssM128Cache = new m128();
public static m128* sqrtssM128CachePointer;
private static IntPtr sqrtssCodePointer;
private static sqrtssDelegate sqrtssDele;
private static byte[] sqrtssCodeBytes
= new byte[]
{
0x48,0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // mov rax, [pointer location]
0x48,0x8b,0x00, // mov rax, [rax]
0xf3,0x0f,0x6f,0x00, // movqdu xmm0,xmmword ptr [rax]
0xf3,0x0f,0x51,0xc0, // sqrtss xmm0,xmm0
0xf3,0x0f,0x7f,0x00 // movdqu xmmword ptr [rax],xmm0
internal static readonly byte[] SqrtssCodeBytes = new byte[] {
0x48, 0x89, 0xc8, //mov rax,rcx
0xf3, 0x0f, 0x6f, 0x00, //movdqu xmm0,xmmword ptr [rax]
//0x66, 0x0f, 0x6f, 0x00, //movdqa xmm0,xmmword ptr [rax]
0xf3,0x0f, 0x51, 0xc0, //sqrtss xmm0,xmm0
0xf3, 0x0f, 0x7f, 0x00, //movdqu xmmqord ptr [rax],xmm0
//0x66, 0x0f, 0x7f, 0x00, //movdqa xmmword ptr [rax],xmm0
0xc3, //ret
};
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr VirtualAlloc(
IntPtr lpAddress,
UIntPtr dwSize,
AllocationType flAllocationType,
MemoryProtection flProtect
);
[DllImport("kernel32")]
private static extern bool VirtualFree(
IntPtr lpAddress,
UInt32 dwSize,
UInt32 dwFreeType
);
static asmfuncDelegate sqrtssDelegate;
[Flags()]
protected enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
TOP_DOWN = 0x100000,
WRITE_WATCH = 0x200000
}
[Flags()]
protected enum MemoryProtection : uint
{
EXECUTE = 0x10,
EXECUTE_READ = 0x20,
EXECUTE_READWRITE = 0x40,
EXECUTE_WRITECOPY = 0x80,
NOACCESS = 0x01,
READONLY = 0x02,
READWRITE = 0x04,
WRITECOPY = 0x08,
GUARD_Modifierflag = 0x100,
NOCACHE_Modifierflag = 0x200,
WRITECOMBINE_Modifierflag = 0x400
}
private unsafe static void InitSqrtss()
{
byte[] sqrtssM128PointerBytes = BitConverter.GetBytes((ulong)sqrtssM128CachePointer);
for (int i = 0; i < sqrtssM128PointerBytes.Length; i++)
{
sqrtssCodeBytes[2+i] = sqrtssCodeBytes[7-i];
}
if (IntPtr.Size!=8)
{
throw new Exception("This SSE class support 64bits OS only presently!");
}
sqrtssCodePointer = VirtualAlloc(
private static IntPtr sqrtssHandle = VirtualAlloc(
IntPtr.Zero,
new UIntPtr((uint)sqrtssCodeBytes.Length),
AllocationType.COMMIT | AllocationType.RESERVE,
MemoryProtection.EXECUTE_READWRITE
);
SqrtssCodeBytes.Length,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
Marshal.Copy(sqrtssCodeBytes, 0, sqrtssCodePointer, sqrtssCodeBytes.Length);
sqrtssDele = (sqrtssDelegate)Marshal.GetDelegateForFunctionPointer(sqrtssCodePointer,typeof(sqrtssDelegate));
private static void InitSqrtss()
{
Marshal.Copy(SqrtssCodeBytes,0,sqrtssHandle,SqrtssCodeBytes.Length);
sqrtssDelegate = Marshal.GetDelegateForFunctionPointer(sqrtssHandle,typeof(asmfuncDelegate)) as asmfuncDelegate;
}
public static float Sqrtss(float a)
public unsafe static m128 Sqrtss(m128* m)
{
fixed (m128* p = &sqrtssM128Cache)
{
sqrtssM128Cache.float0 = a;
sqrtssDele(sqrtssM128Cache);
return sqrtssM128Cache.float0;
}
sqrtssDelegate((ulong)m);
return *m;
}
}
[UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)]
internal delegate void sqrtssDelegate(m128 a);
/// <summary>
/// A delegate for asm sse functions
/// </summary>
/// <param name="m128Pointrter">The m128* pointer to the target m128 transformed in ulong form</param>
[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
internal delegate void asmfuncDelegate(ulong m128Pointrter);
}
+11 -3
View File
@@ -1,18 +1,26 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Optimization
{
public static unsafe partial class SSE
{
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
private static extern bool VirtualFree(IntPtr address, int size, uint freeType);
const uint MEM_COMMIT = 0x1000;
const uint MEM_RESERVE = 0x2000;
const uint PAGE_EXECUTE_READWRITE = 0x40;
const uint MEM_RELEASE = 0x8000;
static SSE()
{
//编译模拟Sqrtss指令
var sqrtssCachePointer = stackalloc ulong[1];
InitSqrtss();
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ using System.Text;
namespace StgSharp.Optimization
{
[StructLayout(LayoutKind.Explicit,Size =16)]
[StructLayout(LayoutKind.Explicit,Size =16,Pack =16)]
public struct m128
{
[FieldOffset(0)] public float float0;