Add debug view resource tests
このコミットが含まれているのは:
1 親
da90dd9157
コミット
21ae8a57bc
6ファイル変更
+336
-4
検索条件に一致するファイルはありません
@@ -18,7 +18,7 @@ internal sealed class BufferDebugView<T>
|
||||
{
|
||||
if (buffer is not null)
|
||||
{
|
||||
var items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
T[] items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
|
||||
buffer.CopyTo(ref items[0], 0, buffer.Length);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ internal sealed class Texture2DDebugView<T>
|
||||
{
|
||||
if (texture is not null)
|
||||
{
|
||||
var items = new T[texture.Height, texture.Width];
|
||||
T[,] items = new T[texture.Height, texture.Width];
|
||||
|
||||
texture.CopyTo(ref items[0, 0], items.Length, 0, 0, texture.Width, texture.Height);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ internal sealed class Texture3DDebugView<T>
|
||||
{
|
||||
if (texture is not null)
|
||||
{
|
||||
var items = new T[texture.Depth, texture.Height, texture.Width];
|
||||
T[,,] items = new T[texture.Depth, texture.Height, texture.Width];
|
||||
|
||||
texture.CopyTo(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ internal sealed class TransferBufferDebugView<T>
|
||||
{
|
||||
if (buffer is not null)
|
||||
{
|
||||
var items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
T[] items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
|
||||
buffer.Span.CopyTo(items);
|
||||
|
||||
|
||||
@@ -19,4 +19,15 @@
|
||||
PrivateAssets="contentfiles;build"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AdditionalResourceAttribute.cs" Link="Attributes\AdditionalResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AllDevicesAttribute.cs" Link="Attributes\AllDevicesAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\CombinatorialTestMethodAttribute.cs" Link="Attributes\CombinatorialTestMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DataAttribute.cs" Link="Attributes\DataAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DeviceAttribute.cs" Link="Attributes\DeviceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\ResourceAttribute.cs" Link="Attributes\ResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\DeviceExtensions.cs" Link="Extensions\DeviceExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\GraphicsDeviceExtensions.cs" Link="Extensions\GraphicsDeviceExtensions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,321 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Debug;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.Internals;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("Buffer")]
|
||||
public partial class DebugViewTests
|
||||
{
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(32)]
|
||||
[Data(256)]
|
||||
[Data(1024)]
|
||||
public void BufferDebugView_NotNull(Device device, Type bufferType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, data);
|
||||
|
||||
BufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BufferDebugView_Null()
|
||||
{
|
||||
using Buffer<float> buffer = null!;
|
||||
|
||||
BufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(32, 32)]
|
||||
[Data(1024, 1024)]
|
||||
[Data(667, 480)]
|
||||
public void Texture2DDebugView_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, width * height).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, data, width, height);
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(32, 32)]
|
||||
[Data(512, 512)]
|
||||
[Data(667, 480)]
|
||||
public void Texture2DDebugView_WithTPixel_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
Random random = new(42);
|
||||
Rgba32[,] data = new Rgba32[height, width];
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[i, j] = new Rgba32((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
}
|
||||
}
|
||||
|
||||
using Texture2D<Rgba32> texture = device.Get().AllocateTexture2D<Rgba32, float4>(textureType, width, height);
|
||||
|
||||
texture.CopyFrom(data);
|
||||
|
||||
Texture2DDebugView<Rgba32> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Texture2DDebugView_Null()
|
||||
{
|
||||
using Texture2D<float> texture = null!;
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void Texture3DDebugView_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, width * height * depth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, data, width, height, depth);
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<,>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void Texture3DDebugView_WithTPixel_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
Random random = new(42);
|
||||
Rgba32[,,] data = new Rgba32[depth, height, width];
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[k, i, j] = new Rgba32((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using Texture3D<Rgba32> texture = device.Get().AllocateTexture3D<Rgba32, float4>(textureType, width, height, depth);
|
||||
|
||||
texture.CopyFrom(data);
|
||||
|
||||
Texture3DDebugView<Rgba32> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Texture3DDebugView_Null()
|
||||
{
|
||||
using Texture3D<float> texture = null!;
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
[Data(32)]
|
||||
[Data(1024)]
|
||||
[Data(667)]
|
||||
public void TransferBufferDebugView_NotNull(Device device, Type bufferType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, size);
|
||||
|
||||
data.AsSpan().CopyTo(buffer.Span);
|
||||
|
||||
TransferBufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferBufferDebugView_Null()
|
||||
{
|
||||
using TransferBuffer<float> buffer = null!;
|
||||
|
||||
TransferBufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[Data(32, 32)]
|
||||
[Data(1024, 1024)]
|
||||
[Data(667, 480)]
|
||||
public void TransferTexture2DDebugView_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
Random random = new(42);
|
||||
float[,] data = new float[height, width];
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[i, j] = random.NextSingle();
|
||||
}
|
||||
}
|
||||
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(textureType, width, height);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
Span<float> row = texture.View.GetRowSpan(i);
|
||||
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
row[j] = data[i, j];
|
||||
}
|
||||
}
|
||||
|
||||
TransferTexture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferTexture2DDebugView_Null()
|
||||
{
|
||||
using Texture2D<float> texture = null!;
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void TransferTexture3DDebugView_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
Random random = new(42);
|
||||
float[,,] data = new float[depth, height, width];
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[k, i, j] = random.NextSingle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(textureType, width, height, depth);
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
Span<float> row = texture.View.GetRowSpan(i, k);
|
||||
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
row[j] = data[k, i, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TransferTexture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferTexture3DDebugView_Null()
|
||||
{
|
||||
using Texture3D<float> texture = null!;
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする