diff --git a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs index 91a20ff3..b1a846f6 100644 --- a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs @@ -108,6 +108,27 @@ public static class GraphicsResourceHelper return *(ulong*)&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. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadOnlyTexture2D texture, GraphicsDevice device) + where T : 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. /// @@ -188,6 +209,27 @@ public static class GraphicsResourceHelper return *(ulong*)&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. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe ulong ValidateAndGetGpuDescriptorHandle(IReadOnlyTexture3D texture, GraphicsDevice device) + where T : 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. ///