Add new APIs to copy between Texture2D<T>-s
このコミットが含まれているのは:
1 親
16c067ed34
コミット
aef6630709
4ファイル変更
+448
-3
検索条件に一致するファイルはありません
@@ -45,7 +45,9 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 && sourceY == 0 && sourceZ == 0 &&
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12ResourceDescriptionSource.Width &&
|
||||
height == d3D12ResourceDescriptionSource.Height &&
|
||||
depth == d3D12ResourceDescriptionSource.Depth)
|
||||
@@ -103,7 +105,9 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 && sourceY == 0 && sourceZ == 0 &&
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12PlacedSubresourceFootprintSource->Footprint.Width &&
|
||||
height == d3D12PlacedSubresourceFootprintSource->Footprint.Height &&
|
||||
depth == d3D12PlacedSubresourceFootprintSource->Footprint.Depth)
|
||||
@@ -125,6 +129,65 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
pD3D12Box);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a texture memory region from one texture to another.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
|
||||
/// <param name="d3D12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a buffer) to write to.</param>
|
||||
/// <param name="destinationX">The horizontal offset in the destination buffer.</param>
|
||||
/// <param name="destinationY">The vertical offset in the destination buffer.</param>
|
||||
/// <param name="destinationZ">The depthwise offset in the destination buffer.</param>
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a texture) to read from.</param>
|
||||
/// <param name="sourceX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to read from.</param>
|
||||
/// <param name="height">The height of the memory area to read from.</param>
|
||||
/// <param name="depth">The depth of the memory area to read from.</param>
|
||||
public static void CopyTextureRegion(
|
||||
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
|
||||
ID3D12Resource* d3D12ResourceDestination,
|
||||
uint destinationX,
|
||||
uint destinationY,
|
||||
ushort destinationZ,
|
||||
ID3D12Resource* d3D12ResourceSource,
|
||||
uint sourceX,
|
||||
uint sourceY,
|
||||
ushort sourceZ,
|
||||
uint width,
|
||||
uint height,
|
||||
ushort depth)
|
||||
{
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescriptionSource = d3D12ResourceSource->GetDesc();
|
||||
D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0);
|
||||
D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0);
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12ResourceDescriptionSource.Width &&
|
||||
height == d3D12ResourceDescriptionSource.Height &&
|
||||
depth == d3D12ResourceDescriptionSource.Depth)
|
||||
{
|
||||
pD3D12Box = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3D12Box = new D3D12_BOX((int)sourceX, (int)sourceY, sourceZ, (int)(sourceX + width), (int)(sourceY + height), sourceZ + depth);
|
||||
pD3D12Box = &d3D12Box;
|
||||
}
|
||||
|
||||
d3D12GraphicsCommandList.CopyTextureRegion(
|
||||
&d3D12TextureCopyLocationDestination,
|
||||
destinationX,
|
||||
destinationY,
|
||||
destinationZ,
|
||||
&d3D12TextureCopyLocationSource,
|
||||
pD3D12Box);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a resource barrier to transition a resource to a specific state.
|
||||
/// </summary>
|
||||
|
||||
@@ -177,6 +177,52 @@ public static class Texture2DExtensions
|
||||
source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{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="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{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="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical 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>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
@@ -358,6 +404,52 @@ public static class Texture2DExtensions
|
||||
destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{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="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{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="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical 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>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
@@ -367,7 +459,7 @@ public static class Texture2DExtensions
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, UploadTexture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -223,6 +223,74 @@ 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="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>
|
||||
/// <param name="sourceOffsetY">The vertical 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>
|
||||
internal void CopyTo(Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
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,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
sourceZ: 0,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
1);
|
||||
|
||||
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="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -165,6 +165,228 @@ public partial class Texture2DTests
|
||||
texture.CopyTo(result, x, y, width, height);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 127, 256, 0, 0, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 127, 256, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 122, 329, 127, 256, 512, 480)]
|
||||
[Data(512, 480, 1024, 768, 122, 29, 127, 256, 256, 320)]
|
||||
[Data(512, 480, 256, 256, 122, 120, 0, 0, 256, 256)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 256, 256, 512, 512)]
|
||||
public void CopyTo_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D(sourceType, array, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceHeight, sourceWidth);
|
||||
ReadOnlySpan2D<float> result = destination.ToArray();
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 2055, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 3920)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, -1, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, -2)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, int.MaxValue)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(512, 512, 512, 512, 450, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 450, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 450, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, 450, 128, 128)]
|
||||
[Data(512, 512, 512, 512, -1, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, -1, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, -1, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, -1, 128, 128)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D<float>(sourceType, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 127, 256, 0, 0, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 127, 256, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 122, 329, 127, 256, 512, 480)]
|
||||
[Data(512, 480, 1024, 768, 122, 29, 127, 256, 256, 320)]
|
||||
[Data(512, 480, 256, 256, 122, 120, 0, 0, 256, 256)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 256, 256, 512, 512)]
|
||||
public void CopyFrom_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D(sourceType, array, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceHeight, sourceWidth);
|
||||
ReadOnlySpan2D<float> result = destination.ToArray();
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 2055, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 3920)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, -1, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, -2)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, int.MaxValue)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(512, 512, 512, 512, 450, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 450, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 450, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, 450, 128, 128)]
|
||||
[Data(512, 512, 512, 512, -1, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, -1, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, -1, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, -1, 128, 128)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyFrom_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D<float>(sourceType, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture2D(Device device)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする