Added polyfills to vector/matrix types in SG project

このコミットが含まれているのは:
Sergio Pedri committed 2021-03-11 15:38:13 +01:00
1 親 042d4c7bef
コミット 32d010faab
24ファイル変更
+195 -42

検索条件に一致するファイルはありません

+25
ファイルの表示
@@ -0,0 +1,25 @@
using System;
namespace ComputeSharp.SourceGenerators.Helpers
{
/// <summary>
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.InteropServices.MemoryMarshal"/> on .NET 5.
/// </summary>
internal static class MemoryMarshal
{
/// <inheritdoc cref="System.Runtime.InteropServices.MemoryMarshal.GetReference{T}(Span{T})"/>
public static ref T GetReference<T>(Span<T> span)
{
return ref System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
}
/// <summary>
/// Creates a new <see cref="Span{T}"/> from a given reference.
/// </summary>
/// <typeparam name="T">The type of reference to wrap.</typeparam>
/// <param name="value">The target reference.</param>
/// <param name="length">The length of the <see cref="Span{T}"/> to create.</param>
/// <returns>A new <see cref="Span{T}"/> wrapping <paramref name="value"/>.</returns>
public static Span<T> CreateSpan<T>(ref T value, int length) => default;
}
}
+18
ファイルの表示
@@ -0,0 +1,18 @@
using System;
namespace ComputeSharp.SourceGenerators.Helpers
{
/// <summary>
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.CompilerServices.RuntimeHelpers"/> on .NET 5.
/// </summary>
internal static class RuntimeHelpers
{
/// <summary>
/// Allocates some memory tied to the lifetime of a specific type.
/// </summary>
/// <param name="type">The type to associate the memory to.</param>
/// <param name="size">The size in byte of the memory to allocate.</param>
/// <returns>A pointer to the allocated memory.</returns>
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => default;
}
}
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+6 -1
ファイルの表示
@@ -10,8 +10,13 @@
void GenerateAllMatrixProperties(string typeName, int elementSize)
{
#>
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+7 -2
ファイルの表示
@@ -1,5 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{
+6 -1
ファイルの表示
@@ -66,8 +66,13 @@ void GenerateVectorProperties(string typeName, int elementSize)
string hlslElementTypeName = elementTypeName.ToLower();
int i = int.Parse(Regex.Match(typeName, @"\d+$").Value);
#>
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0
using System.Runtime.CompilerServices;
#else
using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
#endif
namespace ComputeSharp
{