Fixed build errors, minor code tweaks
このコミットが含まれているのは:
1 親
6748ec03db
コミット
cc53717a9c
12ファイル変更
+71
-84
検索条件に一致するファイルはありません
@@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.Graphics;
|
||||
|
||||
namespace ComputeSharp.Benchmark.Blas
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
|
||||
#if NETSTANDARD2_0
|
||||
using GC = ComputeSharp.System.GC;
|
||||
using GC = Polyfills.GC;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.Graphics.Commands.Interop
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using ComputeSharp.Graphics;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
|
||||
@@ -4,90 +4,84 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace Polyfills
|
||||
{
|
||||
namespace System
|
||||
/// <summary>
|
||||
/// A polyfill class for the <see cref="GC"/> type.
|
||||
/// </summary>
|
||||
internal static class GC
|
||||
{
|
||||
/// <summary>
|
||||
/// A polyfill class for the <see cref="GC"/> type.
|
||||
/// Allocates an array while skipping zero-initialization, if possible.
|
||||
/// </summary>
|
||||
internal static class GC
|
||||
/// <typeparam name="T">Specifies the type of the array element.</typeparam>
|
||||
/// <param name="length">Specifies the length of the array.</param>
|
||||
/// <param name="pinned">Specifies whether the allocated array must be pinned.</param>
|
||||
/// <returns>An array object with uninitialized memory, if possible.</returns>
|
||||
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false)
|
||||
{
|
||||
return new T[length];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill class for the <see cref="MemoryMarshal"/> type.
|
||||
/// </summary>
|
||||
internal static class MemoryMarshal
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a reference to the 0th element of array. If the array is empty, returns
|
||||
/// a reference to where the 0th element would have been stored. Such a reference
|
||||
/// may be used for pinning but must never be dereferenced.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the array elements.</typeparam>
|
||||
/// <param name="array">The array to analyze.</param>
|
||||
/// <returns>Reference to the 0th element in array.</returns>
|
||||
public static ref T GetArrayDataReference<T>(T[] array)
|
||||
{
|
||||
IntPtr offset = TypeInfo<T>.ArrayDataByteOffset;
|
||||
RawObjectData rawObject = Unsafe.As<RawObjectData>(array)!;
|
||||
ref byte r0 = ref rawObject.Data;
|
||||
ref byte r1 = ref Unsafe.AddByteOffset(ref r0, offset);
|
||||
ref T r2 = ref Unsafe.As<byte, T>(ref r1);
|
||||
|
||||
return ref r2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A private generic class to preload type info for arbitrary runtime types.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to load info for.</typeparam>
|
||||
private static class TypeInfo<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Allocates an array while skipping zero-initialization, if possible.
|
||||
/// The byte offset to the first <typeparamref name="T"/> element in a SZ array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Specifies the type of the array element.</typeparam>
|
||||
/// <param name="length">Specifies the length of the array.</param>
|
||||
/// <param name="pinned">Specifies whether the allocated array must be pinned.</param>
|
||||
/// <returns>An array object with uninitialized memory, if possible.</returns>
|
||||
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false)
|
||||
public static readonly IntPtr ArrayDataByteOffset = MeasureArrayDataByteOffset();
|
||||
|
||||
/// <summary>
|
||||
/// Computes the value for <see cref="ArrayDataByteOffset"/>.
|
||||
/// </summary>
|
||||
/// <returns>The value of <see cref="ArrayDataByteOffset"/> for the current runtime.</returns>
|
||||
private static IntPtr MeasureArrayDataByteOffset()
|
||||
{
|
||||
return new T[length];
|
||||
T[] array = new T[1];
|
||||
RawObjectData rawObject = Unsafe.As<RawObjectData>(array)!;
|
||||
ref byte r0 = ref rawObject.Data;
|
||||
ref byte r1 = ref Unsafe.As<T, byte>(ref array[0]);
|
||||
|
||||
return Unsafe.ByteOffset(ref r0, ref r1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Runtime.InteropServices
|
||||
/// <summary>
|
||||
/// Mapping type for a raw object.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
private sealed class RawObjectData
|
||||
{
|
||||
/// <summary>
|
||||
/// A polyfill class for the <see cref="MemoryMarshal"/> type.
|
||||
/// </summary>
|
||||
internal static class MemoryMarshal
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a reference to the 0th element of array. If the array is empty, returns
|
||||
/// a reference to where the 0th element would have been stored. Such a reference
|
||||
/// may be used for pinning but must never be dereferenced.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the array elements.</typeparam>
|
||||
/// <param name="array">The array to analyze.</param>
|
||||
/// <returns>Reference to the 0th element in array.</returns>
|
||||
public static ref T GetArrayDataReference<T>(T[] array)
|
||||
{
|
||||
IntPtr offset = TypeInfo<T>.ArrayDataByteOffset;
|
||||
RawObjectData rawObject = Unsafe.As<RawObjectData>(array)!;
|
||||
ref byte r0 = ref rawObject.Data;
|
||||
ref byte r1 = ref Unsafe.AddByteOffset(ref r0, offset);
|
||||
ref T r2 = ref Unsafe.As<byte, T>(ref r1);
|
||||
|
||||
return ref r2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A private generic class to preload type info for arbitrary runtime types.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to load info for.</typeparam>
|
||||
private static class TypeInfo<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The byte offset to the first <typeparamref name="T"/> element in a SZ array.
|
||||
/// </summary>
|
||||
public static readonly IntPtr ArrayDataByteOffset = MeasureArrayDataByteOffset();
|
||||
|
||||
/// <summary>
|
||||
/// Computes the value for <see cref="ArrayDataByteOffset"/>.
|
||||
/// </summary>
|
||||
/// <returns>The value of <see cref="ArrayDataByteOffset"/> for the current runtime.</returns>
|
||||
private static IntPtr MeasureArrayDataByteOffset()
|
||||
{
|
||||
T[] array = new T[1];
|
||||
RawObjectData rawObject = Unsafe.As<RawObjectData>(array)!;
|
||||
ref byte r0 = ref rawObject.Data;
|
||||
ref byte r1 = ref Unsafe.As<T, byte>(ref array[0]);
|
||||
|
||||
return Unsafe.ByteOffset(ref r0, ref r1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mapping type for a raw object.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
private sealed class RawObjectData
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public byte Data;
|
||||
}
|
||||
}
|
||||
[FieldOffset(0)]
|
||||
public byte Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using FX = TerraFX.Interop.Windows;
|
||||
#if NET5_0
|
||||
using MemoryMarshal = System.Runtime.InteropServices.MemoryMarshal;
|
||||
#else
|
||||
using MemoryMarshal = ComputeSharp.System.Runtime.InteropServices.MemoryMarshal;
|
||||
using MemoryMarshal = Polyfills.MemoryMarshal;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.Resources
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#if NET5_0
|
||||
using GC = System.GC;
|
||||
#else
|
||||
using GC = ComputeSharp.System.GC;
|
||||
using GC = Polyfills.GC;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.Resources.Views
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Extensions;
|
||||
using ComputeSharp.Shaders.Renderer;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Translation.Interop;
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using TerraFX.Interop;
|
||||
#if NET5_0
|
||||
using MemoryMarshal = System.Runtime.InteropServices.MemoryMarshal;
|
||||
#else
|
||||
using MemoryMarshal = ComputeSharp.System.Runtime.InteropServices.MemoryMarshal;
|
||||
using MemoryMarshal = Polyfills.MemoryMarshal;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.Toolkit.Diagnostics;
|
||||
#if NET5_0
|
||||
using GC = System.GC;
|
||||
#else
|
||||
using GC = ComputeSharp.System.GC;
|
||||
using GC = Polyfills.GC;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
|
||||
namespace ComputeSharp
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Graphics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする