diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs index c909e598..61f61fe6 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs @@ -248,7 +248,19 @@ namespace ComputeSharp.Graphics.Buffers.Abstract using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COMPUTE)) { copyCommandList.ResourceBarrier(D3D12Resource, D3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); - copyCommandList.CopyTextureRegion(d3D12Resource.Get(), (uint)Unsafe.SizeOf(), D3D12Resource, DXGIFormatHelper.GetForType(), (uint)x, (uint)y, (uint)width, (uint)height); + + copyCommandList.CopyTextureRegion( + d3D12Resource.Get(), + (uint)Unsafe.SizeOf(), + D3D12Resource, + DXGIFormatHelper.GetForType(), + (uint)x, + (uint)y, + 0, + (uint)width, + (uint)height, + 1); + copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12ResourceState); copyCommandList.ExecuteAndWaitForCompletion(); } @@ -390,7 +402,19 @@ namespace ComputeSharp.Graphics.Buffers.Abstract using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COMPUTE); copyCommandList.ResourceBarrier(D3D12Resource, D3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); - copyCommandList.CopyTextureRegion(D3D12Resource, DXGIFormatHelper.GetForType(), (uint)x, (uint)y, d3D12Resource.Get(), (uint)width, (uint)height, (uint)Unsafe.SizeOf()); + + copyCommandList.CopyTextureRegion( + D3D12Resource, + DXGIFormatHelper.GetForType(), + (uint)x, + (uint)y, + 0, + (uint)width, + (uint)height, + 1, + d3D12Resource.Get(), + (uint)Unsafe.SizeOf()); + copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12ResourceState); copyCommandList.ExecuteAndWaitForCompletion(); } diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs index 2eb12aaa..94472905 100644 --- a/src/ComputeSharp.Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs @@ -98,9 +98,11 @@ namespace ComputeSharp.Graphics.Commands /// The parameter curreently in use by the texture. /// The horizontal offset in the destination texture. /// The vertical offset in the destination texture. - /// The source (a buffer) to read from. + /// The depthwise offset in the destination texture. /// The width of the memory area to write to. /// The height of the memory area to write to. + /// The depth of the memory area to write to. + /// The source (a buffer) to read from. /// The size of each element to copy. public readonly void CopyTextureRegion( @@ -108,12 +110,14 @@ namespace ComputeSharp.Graphics.Commands DXGI_FORMAT dxgiFormat, uint x, uint y, - ID3D12Resource* d3D12ResourceSource, + ushort z, uint width, uint height, + ushort depth, + ID3D12Resource* d3D12ResourceSource, uint elementSizeInBytes) { - this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, dxgiFormat, x, y, d3D12ResourceSource, width, height, elementSizeInBytes); + this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, dxgiFormat, x, y, z, width, height, depth, d3D12ResourceSource, elementSizeInBytes); } /// @@ -134,10 +138,12 @@ namespace ComputeSharp.Graphics.Commands DXGI_FORMAT dxgiFormat, uint x, uint y, + ushort z, uint width, - uint height) + uint height, + ushort depth) { - this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, elementSizeInBytes, d3D12ResourceSource, dxgiFormat, x, y, width, height); + this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, elementSizeInBytes, d3D12ResourceSource, dxgiFormat, x, y, z, width, height, depth); } /// diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs index 4f7effdd..1c52d59e 100644 --- a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs @@ -16,9 +16,11 @@ namespace ComputeSharp.Graphics.Extensions /// The parameter curreently in use by the texture. /// The horizontal offset in the destination texture. /// The vertical offset in the destination texture. - /// The source (a buffer) to read from. + /// The depthwise offset in the destination texture. /// The width of the memory area to write to. /// The height of the memory area to write to. + /// The depth of the memory area to write to. + /// The source (a buffer) to read from. /// The size of each element to copy. public static void CopyTextureRegion( @@ -27,17 +29,19 @@ namespace ComputeSharp.Graphics.Extensions DXGI_FORMAT dxgiFormat, uint x, uint y, - ID3D12Resource* d3D12ResourceSource, + ushort z, uint width, uint height, + ushort depth, + ID3D12Resource* d3D12ResourceSource, uint elementSizeInBytes) { D3D12_SUBRESOURCE_FOOTPRINT d3D12SubresourceFootprint = new( dxgiFormat, width, height, - 1, - (elementSizeInBytes * width + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)); + depth, + (elementSizeInBytes * width * depth + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)); D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint; d3D12PlacedSubresourceFootprint.Offset = 0; d3D12PlacedSubresourceFootprint.Footprint = d3D12SubresourceFootprint; @@ -45,7 +49,7 @@ namespace ComputeSharp.Graphics.Extensions d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0), d3D12TextureCopyLocationSource = new(d3D12ResourceSource, d3D12PlacedSubresourceFootprint); - d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, 0, &d3D12TextureCopyLocationSource, null); + d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, z, &d3D12TextureCopyLocationSource, null); } /// @@ -56,10 +60,12 @@ namespace ComputeSharp.Graphics.Extensions /// The size of each element to copy. /// The source (a texture) to read from. /// The parameter curreently in use by the texture. - /// The horizontal offset in the destination texture. - /// The vertical offset in the destination texture. - /// The width of the memory area to write to. - /// The height of the memory area to write to. + /// 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 read from. + /// The height of the memory area to read from. + /// The depth of the memory area to read from. public static void CopyTextureRegion( this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12ResourceDestination, @@ -68,22 +74,24 @@ namespace ComputeSharp.Graphics.Extensions DXGI_FORMAT dxgiFormat, uint x, uint y, + ushort z, uint width, - uint height) + uint height, + ushort depth) { D3D12_SUBRESOURCE_FOOTPRINT d3D12SubresourceFootprint = new( dxgiFormat, width, height, - 1, - (elementSizeInBytes * width + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)); + depth, + (elementSizeInBytes * width * depth + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)); D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint; d3D12PlacedSubresourceFootprint.Offset = 0; d3D12PlacedSubresourceFootprint.Footprint = d3D12SubresourceFootprint; D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, d3D12PlacedSubresourceFootprint), d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0); - D3D12_BOX d3D12Box = new((int)x, (int)y, (int)(x + width), (int)(y + height)); + D3D12_BOX d3D12Box = new((int)x, (int)y, z, (int)(x + width), (int)(y + height), z + depth); d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, 0, 0, 0, &d3D12TextureCopyLocationSource, &d3D12Box); }