Added normalized pixel texture allocation tests
このコミットが含まれているのは:
1 親
1ac1f6afdd
コミット
5d816d0e99
3ファイル変更
+225
検索条件に一致するファイルはありません
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
@@ -52,6 +55,29 @@ namespace ComputeSharp.Tests.Extensions
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="Texture2D{T}"/> instance of the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items in the texture.</typeparam>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance to allocate the texture for.</param>
|
||||
/// <param name="type">The type of texture to allocate.</param>
|
||||
/// <param name="width">The width of the texture to create.</param>
|
||||
/// <param name="height">The height of the texture to create.</param>
|
||||
/// <returns>A <see cref="Texture2D{T}"/> instance of the requested size.</returns>
|
||||
[Pure]
|
||||
public static Texture2D<T> AllocateTexture2D<T, TPixel>(this GraphicsDevice device, Type type, int width, int height)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
_ when type == typeof(ReadOnlyTexture2D<,>) => device.AllocateReadOnlyTexture2D<T, TPixel>(width, height),
|
||||
_ when type == typeof(ReadWriteTexture2D<,>) => device.AllocateReadWriteTexture2D<T, TPixel>(width, height),
|
||||
_ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="Texture3D{T}"/> instance of the specified type.
|
||||
/// </summary>
|
||||
@@ -74,6 +100,30 @@ namespace ComputeSharp.Tests.Extensions
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="Texture3D{T}"/> instance of the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items in the texture.</typeparam>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance to allocate the texture for.</param>
|
||||
/// <param name="type">The type of texture to allocate.</param>
|
||||
/// <param name="width">The width of the texture to create.</param>
|
||||
/// <param name="height">The height of the texture to create.</param>
|
||||
/// <param name="depth">The depth of the texture to create.</param>
|
||||
/// <returns>A <see cref="Texture3D{T}"/> instance of the requested size.</returns>
|
||||
[Pure]
|
||||
public static Texture3D<T> AllocateTexture3D<T, TPixel>(this GraphicsDevice device, Type type, int width, int height, int depth)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
_ when type == typeof(ReadOnlyTexture3D<,>) => device.AllocateReadOnlyTexture3D<T, TPixel>(width, height, depth),
|
||||
_ when type == typeof(ReadWriteTexture3D<,>) => device.AllocateReadWriteTexture3D<T, TPixel>(width, height, depth),
|
||||
_ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="Buffer{T}"/> instance of the specified type.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R16), typeof(double))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R8), typeof(double))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Double2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Double2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R16), typeof(double))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R8), typeof(double))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Double2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Double2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Double4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
|
||||
{
|
||||
static void Test<T, TPixel>(Type textureType)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
using Texture2D<T> texture = Gpu.Default.AllocateTexture2D<T, TPixel>(textureType, 128, 128);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
|
||||
if (textureType == typeof(ReadOnlyTexture2D<,>))
|
||||
{
|
||||
Assert.IsTrue(texture is ReadOnlyTexture2D<T, TPixel>);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(texture is ReadWriteTexture2D<T, TPixel>);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
|
||||
}
|
||||
catch (TargetInvocationException e) when (e.InnerException is not null)
|
||||
{
|
||||
throw e.InnerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R16), typeof(double))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R8), typeof(double))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Double2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Double2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R16), typeof(double))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R8), typeof(double))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Double2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Double2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Double4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Double4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
|
||||
{
|
||||
static void Test<T, TPixel>(Type textureType)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
using Texture3D<T> texture = Gpu.Default.AllocateTexture3D<T, TPixel>(textureType, 128, 128, 2);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreEqual(texture.Depth, 2);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
|
||||
if (textureType == typeof(ReadOnlyTexture3D<,>))
|
||||
{
|
||||
Assert.IsTrue(texture is ReadOnlyTexture3D<T, TPixel>);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(texture is ReadWriteTexture3D<T, TPixel>);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
|
||||
}
|
||||
catch (TargetInvocationException e) when (e.InnerException is not null)
|
||||
{
|
||||
throw e.InnerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする