diff --git a/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj b/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj index fb8c0b90..16e8e2af 100644 --- a/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj +++ b/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj @@ -14,7 +14,4 @@ - - - diff --git a/src/ComputeSharp.D2D1Interop/Extensions/ComPtrExtensions.cs b/src/ComputeSharp.D2D1Interop/Extensions/ComPtrExtensions.cs index 2d473c06..6abbb717 100644 --- a/src/ComputeSharp.D2D1Interop/Extensions/ComPtrExtensions.cs +++ b/src/ComputeSharp.D2D1Interop/Extensions/ComPtrExtensions.cs @@ -9,6 +9,20 @@ namespace ComputeSharp.D2D1Interop.Extensions; /// Trimmed down version of the same file in ComputeSharp. internal static class ComPtrExtensions { + /// + /// Gets the address of the current instance as a raw double pointer. + /// + /// The type to wrap in the current instance. + /// The input instance to get the address for. + /// The raw pointer to the input instance. + /// This method is only valid when the current instance is on the stack or pinned. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe void** GetVoidAddressOf(this in ComPtr ptr) + where T : unmanaged, IUnknown.Interface + { + return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr)); + } + /// /// Moves the current instance and resets it without releasing the reference. /// diff --git a/src/ComputeSharp.D2D1Interop/Helpers/ThrowHelper.cs b/src/ComputeSharp.D2D1Interop/Helpers/ThrowHelper.cs new file mode 100644 index 00000000..e9e0fab1 --- /dev/null +++ b/src/ComputeSharp.D2D1Interop/Helpers/ThrowHelper.cs @@ -0,0 +1,43 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace ComputeSharp.D2D1Interop.Helpers; + +/// +/// Helper methods to efficiently throw exceptions. +/// +internal static partial class ThrowHelper +{ + /// + /// Throws a new . + /// + /// The argument name. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string? name) + { + throw new ArgumentOutOfRangeException(name); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string? message) + { + throw new InvalidOperationException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string? message) + { + throw new NotSupportedException(message); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs b/src/ComputeSharp.D2D1Interop/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs index e18934db..115d5dab 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs @@ -1,9 +1,9 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using CommunityToolkit.Diagnostics; using ComputeSharp.__Internals; -using ComputeSharp.Core.Extensions; +using ComputeSharp.D2D1Interop.Extensions; +using ComputeSharp.D2D1Interop.Helpers; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Buffers/PinnedBufferMemoryManager.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Buffers/PinnedBufferMemoryManager.cs index 788e6516..96163845 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Buffers/PinnedBufferMemoryManager.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Buffers/PinnedBufferMemoryManager.cs @@ -2,7 +2,7 @@ using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using CommunityToolkit.Diagnostics; +using ComputeSharp.D2D1Interop.Helpers; namespace ComputeSharp.D2D1Interop.Shaders.Interop.Buffers; @@ -40,7 +40,10 @@ internal sealed unsafe class PinnedBufferMemoryManager : MemoryManager /// public override unsafe MemoryHandle Pin(int elementIndex = 0) { - Guard.IsInRange(elementIndex, 0, this.length); + if ((uint)elementIndex >= this.length) + { + ThrowHelper.ThrowArgumentOutOfRangeException(nameof(elementIndex)); + } return new(this.buffer + elementIndex); } diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1ReflectionServices.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1ReflectionServices.cs index f0e4f0ac..1691f883 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1ReflectionServices.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1ReflectionServices.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using ComputeSharp.Core.Extensions; using ComputeSharp.D2D1Interop; +using ComputeSharp.D2D1Interop.Extensions; using ComputeSharp.Shaders.Dispatching; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; diff --git a/src/ComputeSharp.D2D1Interop/TemporaryPolifylls.cs b/src/ComputeSharp.D2D1Interop/TemporaryPolifylls.cs new file mode 100644 index 00000000..975db967 --- /dev/null +++ b/src/ComputeSharp.D2D1Interop/TemporaryPolifylls.cs @@ -0,0 +1,34 @@ +using System; + +namespace ComputeSharp +{ + /// + /// Placeholder. + /// + public struct Float4 + { + } + + /// + /// Placeholder. + /// + public struct Float2 + { + } +} + +namespace ComputeSharp.Exceptions +{ + /// + /// Placeholder. + /// + public sealed class InvalidExecutionContextException : Exception + { + /// + /// Placeholder. + /// + public InvalidExecutionContextException(string name) + { + } + } +} diff --git a/src/ComputeSharp/Properties/AssemblyInfo.cs b/src/ComputeSharp/Properties/AssemblyInfo.cs index ebbe6d87..80e60132 100644 --- a/src/ComputeSharp/Properties/AssemblyInfo.cs +++ b/src/ComputeSharp/Properties/AssemblyInfo.cs @@ -3,7 +3,6 @@ [module: SkipLocalsInit] [assembly: InternalsVisibleTo("ComputeSharp.Dynamic")] -[assembly: InternalsVisibleTo("ComputeSharp.D2D1Interop")] [assembly: InternalsVisibleTo("ComputeSharp.Uwp")] [assembly: InternalsVisibleTo("ComputeSharp.WinUI")]