diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs index ed5d771b..80825945 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs @@ -214,11 +214,13 @@ namespace ComputeSharp.Resources /// Reads the contents of the specified range from the current instance and writes them into a target instance. /// /// The target instance to write data to. - /// The horizontal offset in the source texture. - /// The vertical offset in the source texture. + /// The horizontal offset within . + /// The vertical offset within . + /// The horizontal offset in the source texture. + /// The vertical offset in the source texture. /// The width of the memory area to copy. /// The height of the memory area to copy. - internal void CopyTo(ReadBackTexture2D destination, int x, int y, int width, int height) + internal void CopyTo(ReadBackTexture2D destination, int destinationX, int destinationY, int sourceX, int sourceY, int width, int height) { GraphicsDevice.ThrowIfDisposed(); @@ -227,14 +229,18 @@ namespace ComputeSharp.Resources destination.ThrowIfDeviceMismatch(GraphicsDevice); destination.ThrowIfDisposed(); - Guard.IsInRange(x, 0, Width, nameof(x)); - Guard.IsInRange(y, 0, Height, nameof(y)); + Guard.IsInRange(destinationX, 0, destination.Width, nameof(destinationX)); + Guard.IsInRange(destinationY, 0, destination.Height, nameof(destinationY)); + Guard.IsInRange(sourceX, 0, Width, nameof(sourceX)); + Guard.IsInRange(sourceY, 0, Height, nameof(sourceY)); 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.IsLessThanOrEqualTo(x + width, Width, nameof(x)); - Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); + Guard.IsBetweenOrEqualTo(destinationX + width, 1, destination.Width, nameof(destinationX)); + Guard.IsBetweenOrEqualTo(destinationY + height, 1, destination.Height, nameof(destinationY)); + Guard.IsLessThanOrEqualTo(sourceX + width, Width, nameof(sourceX)); + Guard.IsLessThanOrEqualTo(sourceY + height, Height, nameof(sourceY)); using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType); @@ -248,12 +254,12 @@ namespace ComputeSharp.Resources copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( d3D12ResourceDestination: destination.D3D12Resource, d3D12PlacedSubresourceFootprintDestination, - destinationX: 0, - destinationY: 0, + (uint)destinationX, + (uint)destinationY, destinationZ: 0, d3D12ResourceSource: D3D12Resource, - sourceX: (uint)x, - sourceY: (uint)y, + (uint)sourceX, + (uint)sourceY, sourceZ: 0, (uint)width, (uint)height, diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs index 78980eb0..34dfe533 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs @@ -232,13 +232,16 @@ namespace ComputeSharp.Resources /// Reads the contents of the specified range from the current instance and writes them into a instance. /// /// The target instance to write data to. - /// The horizontal offset in the source texture. - /// The vertical offset in the source texture. - /// The depthwise offset in the source texture. + /// The horizontal offset within . + /// The vertical offset within . + /// The depthwise offset within . + /// The horizontal offset in the source texture. + /// The vertical offset in the source texture. + /// The depthwise offset in the source texture. /// The width of the memory area to copy. /// The height of the memory area to copy. /// The depth of the memory area to copy. - internal void CopyTo(ReadBackTexture3D destination, int x, int y, int z, int width, int height, int depth) + internal void CopyTo(ReadBackTexture3D destination, int destinationX, int destinationY, int destinationZ, int sourceX, int sourceY, int sourceZ, int width, int height, int depth) { GraphicsDevice.ThrowIfDisposed(); @@ -247,18 +250,24 @@ namespace ComputeSharp.Resources destination.ThrowIfDeviceMismatch(GraphicsDevice); destination.ThrowIfDisposed(); - Guard.IsInRange(x, 0, Width, nameof(x)); - Guard.IsInRange(y, 0, Height, nameof(y)); - Guard.IsInRange(z, 0, Depth, nameof(z)); + Guard.IsInRange(destinationX, 0, destination.Width, nameof(destinationX)); + Guard.IsInRange(destinationY, 0, destination.Height, nameof(destinationY)); + Guard.IsInRange(destinationZ, 0, destination.Depth, nameof(destinationZ)); + Guard.IsInRange(sourceX, 0, Width, nameof(sourceX)); + Guard.IsInRange(sourceY, 0, Height, nameof(sourceY)); + Guard.IsInRange(sourceZ, 0, Depth, nameof(sourceZ)); 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.IsLessThanOrEqualTo(x + width, Width, nameof(x)); - Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); - Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z)); + Guard.IsBetweenOrEqualTo(destinationX + width, 1, destination.Width, nameof(destinationX)); + Guard.IsBetweenOrEqualTo(destinationY + height, 1, destination.Height, nameof(destinationY)); + Guard.IsBetweenOrEqualTo(destinationZ + depth, 1, destination.Depth, nameof(destinationZ)); + Guard.IsLessThanOrEqualTo(sourceX + width, Width, nameof(sourceX)); + Guard.IsLessThanOrEqualTo(sourceY + height, Height, nameof(sourceY)); + Guard.IsLessThanOrEqualTo(sourceZ + depth, Depth, nameof(sourceZ)); using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType); @@ -272,13 +281,13 @@ namespace ComputeSharp.Resources copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( d3D12ResourceDestination: destination.D3D12Resource, d3D12PlacedSubresourceFootprintDestination, - destinationX: 0, - destinationY: 0, - destinationZ: 0, + (uint)destinationX, + (uint)destinationY, + (ushort)destinationZ, d3D12ResourceSource: D3D12Resource, - sourceX: (uint)x, - sourceY: (uint)y, - sourceZ: (ushort)z, + (uint)sourceX, + (uint)sourceY, + (ushort)sourceZ, (uint)width, (uint)height, (ushort)depth); diff --git a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs index 09764937..db6722f8 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs @@ -185,7 +185,7 @@ namespace ComputeSharp public static void CopyTo(this Texture2D texture, ReadBackTexture2D destination) where T : unmanaged { - texture.CopyTo(destination, 0, 0, texture.Width, texture.Height); + texture.CopyTo(destination, 0, 0, 0, 0, texture.Width, texture.Height); } /// @@ -201,7 +201,7 @@ namespace ComputeSharp public static void CopyTo(this Texture2D texture, ReadBackTexture2D destination, int x, int y, int width, int height) where T : unmanaged { - texture.CopyTo(destination, x, y, width, height); + texture.CopyTo(destination, 0, 0, x, y, width, height); } /// diff --git a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs index e760251c..83c0837d 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs @@ -159,7 +159,7 @@ namespace ComputeSharp public static void CopyTo(this Texture3D texture, ReadBackTexture3D destination) where T : unmanaged { - texture.CopyTo(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyTo(destination, 0, 0, 0, 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -177,7 +177,7 @@ namespace ComputeSharp public static void CopyTo(this Texture3D texture, ReadBackTexture3D destination, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.CopyTo(destination, x, y, z, width, height, depth); + texture.CopyTo(destination, 0, 0, 0, x, y, z, width, height, depth); } /// diff --git a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs index 664a8fba..cede4b3a 100644 --- a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs +++ b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs @@ -49,7 +49,7 @@ namespace ComputeSharp.Tests [TestMethod] [DataRow(typeof(UploadTexture3D<>))] - //[DataRow(typeof(ReadBackTexture3D<>))] + [DataRow(typeof(ReadBackTexture3D<>))] [ExpectedException(typeof(ObjectDisposedException))] public void UsageAfterDispose(Type bufferType) {