From 62f12ed51094a24c0c7a46b0a0cdbdf68e248e42 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 1 Sep 2022 00:51:14 +0200 Subject: [PATCH] Add missing GraphicsDeviceExtensions test extensions --- .../Extensions/GraphicsDeviceExtensions.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs index 2e8cd78c..d40c81b0 100644 --- a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs +++ b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs @@ -30,6 +30,48 @@ public static class GraphicsDeviceExtensions }; } + /// + /// Allocates a new instance of the specified type. + /// + /// The type of items in the texture. + /// The target instance to allocate the texture for. + /// The type of texture to allocate. + /// The width of the texture to create. + /// The allocation mode to use for the new resource. + /// A instance of the requested size. + public static Texture1D AllocateTexture1D(this GraphicsDevice device, Type type, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged + { + return type switch + { + _ when type == typeof(ReadOnlyTexture1D<>) => device.AllocateReadOnlyTexture1D(width, allocationMode), + _ when type == typeof(ReadWriteTexture1D<>) => device.AllocateReadWriteTexture1D(width, allocationMode), + _ => throw new ArgumentException($"Invalid type: {type}", nameof(type)) + }; + } + + /// + /// Allocates a new instance of the specified type. + /// + /// The type of items in the texture. + /// The type of pixels used on the GPU side. + /// The target instance to allocate the texture for. + /// The type of texture to allocate. + /// The width of the texture to create. + /// The allocation mode to use for the new resource. + /// A instance of the requested size. + public static Texture1D AllocateTexture1D(this GraphicsDevice device, Type type, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + return type switch + { + _ when type == typeof(ReadOnlyTexture1D<,>) => device.AllocateReadOnlyTexture1D(width, allocationMode), + _ when type == typeof(ReadWriteTexture1D<,>) => device.AllocateReadWriteTexture1D(width, allocationMode), + _ => throw new ArgumentException($"Invalid type: {type}", nameof(type)) + }; + } + /// /// Allocates a new instance of the specified type. /// @@ -223,6 +265,25 @@ public static class GraphicsDeviceExtensions }; } + /// + /// Allocates a new instance of the specified type. + /// + /// The type of items in the texture. + /// The target instance to allocate the texture for. + /// The type of texture to allocate. + /// The data to load on the texture. + /// A instance of the requested type. + public static Texture1D AllocateTexture1D(this GraphicsDevice device, Type type, T[] data) + where T : unmanaged + { + return type switch + { + _ when type == typeof(ReadOnlyTexture1D<>) => device.AllocateReadOnlyTexture1D(data), + _ when type == typeof(ReadWriteTexture1D<>) => device.AllocateReadWriteTexture1D(data), + _ => throw new ArgumentException($"Invalid type: {type}", nameof(type)) + }; + } + /// /// Allocates a new instance of the specified type. ///