Add new APIs to copy between Texture3D<T>-s
このコミットが含まれているのは:
1 親
391c809f8d
コミット
3570b4d65e
4ファイル変更
+463
-1
検索条件に一致するファイルはありません
@@ -150,6 +150,57 @@ public static class Texture3DExtensions
|
||||
source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, sourceOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
@@ -351,6 +402,57 @@ public static class Texture3DExtensions
|
||||
destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -226,7 +226,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
|
||||
@@ -240,6 +240,83 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
|
||||
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
|
||||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
? D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
: D3D12_COMMAND_LIST_TYPE_COPY;
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
|
||||
}
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: destination.D3D12Resource,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
(ushort)destinationOffsetZ,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
(ushort)sourceOffsetZ,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
|
||||
}
|
||||
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -194,6 +194,289 @@ public partial class Texture3DTests
|
||||
texture.CopyTo(result, x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 3)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 1, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 1, 512, 512, 2)]
|
||||
// [Data(512, 512, 4, 512, 512, 4, 0, 0, 1, 0, 0, 2, 512, 512, 2)]
|
||||
// This test fails, only on WARP devices, and only if not run on its own. It seems
|
||||
// to be possibly caused by a bug in ID3D12GraphicsCommandList::CopyTextureRegion.
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 2)]
|
||||
public void CopyTo_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth * sourceDepth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D(sourceType, array, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
|
||||
float[,,] stack = destination.ToArray();
|
||||
|
||||
for (int k = 0; k < destinationDepth; k++)
|
||||
{
|
||||
ReadOnlySpan2D<float> result = new(stack, k);
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (k >= destinationOffsetZ &&
|
||||
k < destinationOffsetZ + copyDepth &&
|
||||
i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceZ = k - destinationOffsetZ + sourceOffsetZ;
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceZ * sourceHeight * sourceWidth, sourceHeight, sourceWidth, 0);
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 2055, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, -1, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, int.MaxValue, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 1025, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, -1, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, int.MaxValue, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, 6)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, -1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, int.MaxValue)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 450, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 450, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 5, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 450, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 450, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 4, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, -1, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, -1, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, -1, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, -1, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, -1, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, -1, 128, 128, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D<float>(sourceType, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 3)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 1, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 1, 512, 512, 2)]
|
||||
// [Data(512, 512, 4, 512, 512, 4, 0, 0, 1, 0, 0, 2, 512, 512, 2)]
|
||||
// TODO: see explanation above in CopyTo_TextureToVoid_Ok
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 2)]
|
||||
public void CopyFrom_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth * sourceDepth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D(sourceType, array, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
|
||||
float[,,] stack = destination.ToArray();
|
||||
|
||||
for (int k = 0; k < destinationDepth; k++)
|
||||
{
|
||||
ReadOnlySpan2D<float> result = new(stack, k);
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (k >= destinationOffsetZ &&
|
||||
k < destinationOffsetZ + copyDepth &&
|
||||
i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceZ = k - destinationOffsetZ + sourceOffsetZ;
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceZ * sourceHeight * sourceWidth, sourceHeight, sourceWidth, 0);
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 2055, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, -1, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, int.MaxValue, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 1025, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, -1, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, int.MaxValue, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, 6)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, -1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, int.MaxValue)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 450, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 450, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 5, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 450, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 450, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 4, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, -1, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, -1, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, -1, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, -1, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, -1, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, -1, 128, 128, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyFrom_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D<float>(sourceType, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture3D(Device device)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする