using System; using System.ComponentModel; using System.Runtime.CompilerServices; using ComputeSharp.Resources; using Microsoft.Toolkit.Diagnostics; 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 not intended to be used directly by user code")] public static class GraphicsResourceHelper { /// /// An interface for non-generic graphics resource types. /// internal interface IGraphicsResource { /// /// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The target instance in use. /// The GPU descriptor handle for the resource. D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device); } /// /// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input buffer. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the buffer. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [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 texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ValidateAndGetGpuDescriptorHandle(ReadOnlyTexture2D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); texture.ThrowIfDeviceMismatch(device); return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ValidateAndGetGpuDescriptorHandle(ReadWriteTexture2D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); texture.ThrowIfDeviceMismatch(device); return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of normalized values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadOnlyTexture2D texture, GraphicsDevice device) where TPixel : unmanaged { if (texture is IGraphicsResource resource) { D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device); return *(ulong*)&d3D12GpuDescriptorHandle; } return ThrowHelper.ThrowArgumentException("The input texture is not a valid instance"); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of normalized values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadWriteTexture2D texture, GraphicsDevice device) where TPixel : unmanaged { if (texture is IGraphicsResource resource) { D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device); return *(ulong*)&d3D12GpuDescriptorHandle; } return ThrowHelper.ThrowArgumentException("The input texture is not a valid instance"); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ValidateAndGetGpuDescriptorHandle(ReadOnlyTexture3D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); texture.ThrowIfDeviceMismatch(device); return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ValidateAndGetGpuDescriptorHandle(ReadWriteTexture3D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); texture.ThrowIfDeviceMismatch(device); return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of normalized values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadOnlyTexture3D texture, GraphicsDevice device) where TPixel : unmanaged { if (texture is IGraphicsResource resource) { D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device); return *(ulong*)&d3D12GpuDescriptorHandle; } return ThrowHelper.ThrowArgumentException("The input texture is not a valid instance"); } /// /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of normalized values stored in the input texture. /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadWriteTexture3D texture, GraphicsDevice device) where TPixel : unmanaged { if (texture is IGraphicsResource resource) { D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device); return *(ulong*)&d3D12GpuDescriptorHandle; } return ThrowHelper.ThrowArgumentException("The input texture is not a valid instance"); } } }