diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 5f600fd0..6be5a219 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -48,17 +48,19 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ComputeSharp.Sample.FSharp" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Sample.FSharp.Shaders", "samples\ComputeSharp.Sample.FSharp.Shaders\ComputeSharp.Sample.FSharp.Shaders.csproj", "{1F37A704-3CDF-45BB-8114-ED9137E5F2CF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerraFX.Interop.Windows", "src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.csproj", "{A2F9F841-854C-4341-B2C1-7A0A72EBEC16}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Polyfills", "Polyfills", "{8DCE343F-BA78-4FE1-B562-B57C603A8BAA}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.NetStandard", "src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.shproj", "{A5997814-D8D2-4541-87AC-C3E53CAA67C0}" EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TerraFX.Interop.Windows", "src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.shproj", "{514FF00E-BBF0-4D55-A47C-EEEB6208ADCE}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution + src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 + src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 + src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{7048deea-0a6f-46a0-b951-b682a8f1cb75}*SharedItemsImports = 5 samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{8cefc324-ca6c-4845-9ad9-70b92bd87057}*SharedItemsImports = 13 - src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a2f9f841-854c-4341-b2c1-7a0a72ebec16}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -164,14 +166,6 @@ Global {1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|Any CPU.Build.0 = Release|Any CPU {1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x64.ActiveCfg = Release|Any CPU {1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x64.Build.0 = Release|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Debug|x64.ActiveCfg = Debug|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Debug|x64.Build.0 = Debug|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Release|Any CPU.Build.0 = Release|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Release|x64.ActiveCfg = Release|Any CPU - {A2F9F841-854C-4341-B2C1-7A0A72EBEC16}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -189,6 +183,7 @@ Global {7C625EC4-F599-4350-A915-F046DF2406D3} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} {1F37A704-3CDF-45BB-8114-ED9137E5F2CF} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} {A5997814-D8D2-4541-87AC-C3E53CAA67C0} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA} + {514FF00E-BBF0-4D55-A47C-EEEB6208ADCE} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC} diff --git a/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems b/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems index 0db9f900..ad0b58c0 100644 --- a/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems +++ b/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems @@ -9,15 +9,19 @@ ComputeSharp.NetStandard + + + + + + + + - - - - \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Collections.Generic/DictionaryExtensions.cs b/src/ComputeSharp.NetStandard/System/Collections.Generic/DictionaryExtensions.cs new file mode 100644 index 00000000..8cd8686e --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Collections.Generic/DictionaryExtensions.cs @@ -0,0 +1,28 @@ +namespace System.Collections.Generic; + +/// +/// A helper type with extensions for the type. +/// +internal static class DictionaryExtensions +{ + /// + /// Tries to remove an item from a instance and returns it if present. + /// + /// The type of dictionary keys. + /// The type of dictionary values. + /// The input instance. + /// The lookup key to use. + /// The resulting item, if present. + /// Whether or not an item was found with the given key. + public static bool Remove(this Dictionary dictionary, TKey key, out TValue value) + { + if (dictionary.TryGetValue(key, out value)) + { + _ = dictionary.Remove(key); + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Collections.Generic/QueueExtensions.cs b/src/ComputeSharp.NetStandard/System/Collections.Generic/QueueExtensions.cs new file mode 100644 index 00000000..8ca46f02 --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Collections.Generic/QueueExtensions.cs @@ -0,0 +1,28 @@ +namespace System.Collections.Generic; + +/// +/// A helper type with extensions for the type. +/// +internal static class QueueExtensions +{ + /// + /// Tries to dequeue an item from the input instance. + /// + /// The type of items in the queue. + /// The input queue. + /// The resulting item, if any. + /// Whether or not an item was found. + public static bool TryDequeue(this Queue queue, out T? result) + { + if (queue.Count > 0) + { + result = queue.Dequeue(); + + return true; + } + + result = default!; + + return false; + } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Enum.cs b/src/ComputeSharp.NetStandard/System/Enum.cs new file mode 100644 index 00000000..194096bd --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Enum.cs @@ -0,0 +1,19 @@ +namespace ComputeSharp.NetStandard.System; + +/// +/// A polyfill type that mirrors some methods from on .NET 6. +/// +internal static class Enum +{ + /// + /// Returns the name of the input enum value. + /// + /// Specifies the type of the enum element. + /// The input enum value. + /// The name of . + public static string GetName(T value) + where T : unmanaged, global::System.Enum + { + return global::System.Enum.GetName(typeof(T), value); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/GC.cs b/src/ComputeSharp.NetStandard/System/GC.cs new file mode 100644 index 00000000..cd9c26ac --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/GC.cs @@ -0,0 +1,21 @@ +namespace ComputeSharp.NetStandard.System; + +/// +/// A polyfill type that mirrors some methods from on .NET 6. +/// +internal static class GC +{ + /// + /// Allocate an array while skipping zero-initialization if possible. + /// + /// Specifies the type of the array element. + /// Specifies the length of the array. + /// Specifies whether the allocated array must be pinned. + /// + /// If pinned is set to true, must not be a reference type or a type that contains object references. + /// + public static T[] AllocateUninitializedArray(int length, bool pinned = false) + { + return new T[length]; + } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs b/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs index dd088958..465f1ede 100644 --- a/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs +++ b/src/ComputeSharp.NetStandard/System/IntPtrExtensions.cs @@ -3,18 +3,18 @@ namespace System; /// -/// A polyfill type with extensions for and . +/// A polyfill type with extensions for and . /// internal static class IntPtrExtensions { - /// + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CompareTo(this nint left, nint right) { return left.CompareTo(right); } - /// + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CompareTo(this nuint left, nuint right) { diff --git a/src/ComputeSharp.NetStandard/System/Path.cs b/src/ComputeSharp.NetStandard/System/Path.cs new file mode 100644 index 00000000..654ded4d --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Path.cs @@ -0,0 +1,20 @@ +using System; + +namespace ComputeSharp.NetStandard.System.IO; + +/// +/// A polyfill type that mirrors some methods from on .NET 6. +/// +internal static class Path +{ + /// + /// Returns the extension of the given path. + /// + /// + /// The returned value is an empty if the given path does not include an extension. + /// + public static ReadOnlySpan GetExtension(ReadOnlySpan path) + { + return global::System.IO.Path.GetExtension(path.ToString()).AsSpan(); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs new file mode 100644 index 00000000..7fe883be --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs @@ -0,0 +1,28 @@ +namespace System.Runtime.CompilerServices; + +/// +/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler. +/// +[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + /// The name of the argument that should be passed to the handler. + /// may be used as the name of the receiver in an instance method. + public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = new string[] { argument }; + + /// + /// Initializes a new instance of the class. + /// + /// The names of the arguments that should be passed to the handler. + /// may be used as the name of the receiver in an instance method. + public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) => Arguments = arguments; + + /// + /// Gets the names of the arguments that should be passed to the handler. + /// + /// may be used as the name of the receiver in an instance method. + public string[] Arguments { get; } +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs new file mode 100644 index 00000000..75904a51 --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs @@ -0,0 +1,9 @@ +namespace System.Runtime.CompilerServices; + +/// +/// Indicates the attributed type is to be used as an interpolated string handler. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] +public sealed class InterpolatedStringHandlerAttribute : Attribute +{ +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/SkipLocalsInitAttribute.cs b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/SkipLocalsInitAttribute.cs new file mode 100644 index 00000000..1339a5ae --- /dev/null +++ b/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/SkipLocalsInitAttribute.cs @@ -0,0 +1,27 @@ +namespace System.Runtime.CompilerServices; + +/// +/// Used to indicate to the compiler that the .locals init +/// flag should not be set in method headers. +/// +/// +/// This attribute is unsafe because it may reveal uninitialized memory to +/// the application in certain instances (e.g., reading from uninitialized +/// stackalloc'd memory). If applied to a method directly, the attribute +/// applies to that method and all nested functions (lambdas, local +/// functions) below it. If applied to a type or module, it applies to all +/// methods nested inside. This attribute is intentionally not permitted on +/// assemblies. Use at the module level instead to apply to multiple type +/// declarations. +/// +[AttributeUsage(AttributeTargets.Module + | AttributeTargets.Class + | AttributeTargets.Struct + | AttributeTargets.Interface + | AttributeTargets.Constructor + | AttributeTargets.Method + | AttributeTargets.Property + | AttributeTargets.Event, Inherited = false)] +internal sealed class SkipLocalsInitAttribute : Attribute +{ +} \ No newline at end of file diff --git a/src/ComputeSharp.NetStandard/System/Runtime/InteropServices/MemoryMarshal.cs b/src/ComputeSharp.NetStandard/System/Runtime/InteropServices/MemoryMarshal.cs index fa4d24e1..0c781495 100644 --- a/src/ComputeSharp.NetStandard/System/Runtime/InteropServices/MemoryMarshal.cs +++ b/src/ComputeSharp.NetStandard/System/Runtime/InteropServices/MemoryMarshal.cs @@ -22,6 +22,17 @@ internal static class MemoryMarshal return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(span); } + /// + /// Returns a reference to the 0th element of . 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. + /// + /// is . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ref T GetArrayDataReference(T[] array) + { + return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(array.AsSpan()); + } + /// /// Creates a new from a given reference. /// diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 12a81b4f..59ea54ce 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -14,6 +14,8 @@ manually linking the source files from ComputeSharp\Core in here. We only need them to extract metadata and to match members based on full name, so the types being in the generator assembly are not an issue.--> + + diff --git a/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs b/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs deleted file mode 100644 index 7ae4730f..00000000 --- a/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace ComputeSharp.SourceGenerators.Helpers; - -/// -/// A polyfill type that mirrors some methods from on .NET 5. -/// -internal static class MemoryMarshal -{ - /// - public static ref T GetReference(Span span) - { - return ref System.Runtime.InteropServices.MemoryMarshal.GetReference(span); - } - - /// - /// Creates a new from a given reference. - /// - /// The type of reference to wrap. - /// The target reference. - /// The length of the to create. - /// A new wrapping . - public static Span CreateSpan(ref T value, int length) => default; -} diff --git a/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs b/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs deleted file mode 100644 index 55cafd42..00000000 --- a/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace ComputeSharp.SourceGenerators.Helpers; - -/// -/// A polyfill type that mirrors some methods from on .NET 5. -/// -internal static class RuntimeHelpers -{ - /// - /// Allocates some memory tied to the lifetime of a specific type. - /// - /// The type to associate the memory to. - /// The size in byte of the memory to allocate. - /// A pointer to the allocated memory. - public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => default; -} diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 9043d479..afc0e023 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -1,7 +1,7 @@  - net6.0 + netstandard2.0;net6.0 bin\Release ComputeSharp.xml ComputeSharp @@ -9,9 +9,34 @@ - + + + + + + + + + + + + + + + + + + + + $(NoWarn);1591 + +