diff --git a/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs b/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs new file mode 100644 index 00000000..9d364b20 --- /dev/null +++ b/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs @@ -0,0 +1,62 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using ComputeSharp.Graphics; +using ComputeSharp.Graphics.Buffers.Abstract; +using TerraFX.Interop; + +namespace ComputeSharp.__Internals +{ + /// + /// A helper class with some proxy methods to expose to generated code in external projects. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This type is meant to be used from the source generator only")] + public static class GraphicsResourceHelper + { + /// + /// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle. + /// + /// The input instance to check. + /// The target instance in use. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ValidateAndGetGpuDescriptorHandle(Buffer buffer, GraphicsDevice device) + where T : unmanaged + { + buffer.ThrowIfDisposed(); + buffer.ThrowIfDeviceMismatch(device); + + return Unsafe.As(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle)); + } + + /// + /// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle. + /// + /// The input instance to check. + /// The target instance in use. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ValidateAndGetGpuDescriptorHandle(Texture2D buffer, GraphicsDevice device) + where T : unmanaged + { + buffer.ThrowIfDisposed(); + buffer.ThrowIfDeviceMismatch(device); + + return Unsafe.As(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle)); + } + + /// + /// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle. + /// + /// The input instance to check. + /// The target instance in use. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ValidateAndGetGpuDescriptorHandle(Texture3D buffer, GraphicsDevice device) + where T : unmanaged + { + buffer.ThrowIfDisposed(); + buffer.ThrowIfDeviceMismatch(device); + + return Unsafe.As(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle)); + } + } +}