macro gymnastics to implement storage kernel, buffer op and complex compute panel

This commit is contained in:
Youmu Liu
2025-11-13 19:09:27 +08:00
parent 2dfb4ae86a
commit 1417785726
18 changed files with 373 additions and 383 deletions
-1
View File
@@ -27,7 +27,6 @@
// -----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Internal.OpenGL;
using System;
+1 -1
View File
@@ -27,7 +27,7 @@
// -----------------------------------------------------------------------
global using StgSharp.Internal;
global using StgSharp.Internal.Intrinsic;
global using StgSharp.Internal.OpenGL;
global
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@@ -27,7 +27,7 @@
// -----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Internal.OpenGL;
using StgSharp.Mathematics;
using System;
+1 -1
View File
@@ -31,7 +31,7 @@ using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Internal.OpenGL
namespace StgSharp.Graphics.OpenGL
{
internal delegate void GLVULKANPROCNV();
+5 -5
View File
@@ -41,20 +41,20 @@ namespace StgSharp.HighPerformance
public unsafe struct M512 : IRegisterPresentation
{
[FieldOffset(0)]private fixed byte _buffer[64];
[FieldOffset(0)]private Vector512<float> Vec;
[FieldOffset(0)] private fixed byte _buffer[64];
[FieldOffset(0)] private Vector512<float> Vec;
public ref T AsRef<T>() where T: unmanaged, INumber<T>
public ref T AsRef<T>() where T : unmanaged, INumber<T>
{
return ref Unsafe.As<byte, T>(ref _buffer[0]);
}
public void BroadCastFrom<T>(T value) where T: unmanaged, INumber<T>
public void BroadCastFrom<T>(T value) where T : unmanaged, INumber<T>
{
Vec = Vector512.Create(value).AsSingle();
}
public ref T Member<T>(int index) where T: unmanaged, INumber<T>
public ref T Member<T>(int index) where T : unmanaged, INumber<T>
{
return ref Unsafe.As<byte, T>(ref _buffer[0]);
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="IMatrixPanel"
// file="MatrixPanel"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
@@ -35,11 +35,7 @@ namespace StgSharp.HighPerformance
public interface IMatrixPanel<T> : IDisposable where T: unmanaged,INumber<T>
{
static abstract int KernelColumnCount { get; }
static abstract int KernelRowCount { get; }
static abstract int ElementCount { get; }
static abstract int MaxElementCount { get; }
static abstract nuint Size { get; }
@@ -54,52 +50,26 @@ namespace StgSharp.HighPerformance
/// <typeparam name="T">
/// Type of matrix element.
/// </typeparam>
[InlineArray(16)]
public unsafe struct MatrixPanelSSE<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
{
private MatrixKernel<T> _buffer;
private M128 vector;
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
public MatrixPanelSSE() { }
public static int KernelColumnCount
public static int MaxElementCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
int size = sizeof(T);
return size < 4 ? 2 : 1;
return 16 * 16 / size;
}
}
public static int KernelRowCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
int size = sizeof(T);
return size < 4 ? 2 : 1;
}
}
public static int ElementCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
int size = sizeof(T);
return size < 4 ? 64 / size : 16;
}
}
public static unsafe nuint Size
{
get
{
nuint size = (nuint)sizeof(T);
return size < 4 ? 64 : 16 * size;
}
}
public static unsafe nuint Size { get; } = 16 * 16;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static MatrixPanelSSE<T>* Create()
@@ -130,15 +100,16 @@ namespace StgSharp.HighPerformance
/// <typeparam name="T">
/// Type of matrix element.
/// </typeparam>
[InlineArray(16)]
public unsafe struct MatrixPanelAVX<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
{
private M512 _buffer;
private M256 _buffer;
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
public MatrixPanelAVX() { }
public static unsafe int ElementCount
public static unsafe int MaxElementCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
@@ -148,18 +119,7 @@ namespace StgSharp.HighPerformance
}
}
public static int KernelColumnCount => 2;
public static int KernelRowCount => 2;
public static unsafe nuint Size
{
get
{
nuint size = (nuint)sizeof(T);
return size < 4 ? 128 : 16 * size;
}
}
public static unsafe nuint Size { get; } = 32 * 16;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static MatrixPanelAVX<T>* Create()
@@ -190,6 +150,7 @@ namespace StgSharp.HighPerformance
/// <typeparam name="T">
/// Type of matrix element.
/// </typeparam>
[InlineArray(16)]
public unsafe struct MatrixComputeKernelAVX512<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
{
@@ -198,7 +159,7 @@ namespace StgSharp.HighPerformance
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
public MatrixComputeKernelAVX512() { }
public readonly unsafe int ElementCount
public static unsafe int MaxElementCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
@@ -208,18 +169,7 @@ namespace StgSharp.HighPerformance
}
}
public static int KernelColumnCount { get; }
public static int KernelRowCount { get; }
public static unsafe nuint Size
{
get
{
nuint size = (nuint)sizeof(T);
return size < 4 ? 128 : 16 * size;
}
}
public static unsafe nuint Size { get; } = 32 * 16;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static MatrixComputeKernelAVX512<T>* Create()