diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs index 96570d5b..cf35da6a 100644 --- a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs @@ -457,24 +457,64 @@ namespace ComputeSharp.Graphics.Extensions /// Gets the layout data for a target resource. /// /// The target to use to get the layout info. - /// The value for the target resource. + /// The value to use. + /// The width of the texture resource. + /// The height of the texture resource. /// The resulting layout info for the resource. /// The size in bytes of each row in the resource. /// The total number of bytes for the resource. public static void GetCopyableFootprint( this ref ID3D12Device d3D12Device, - D3D12_RESOURCE_DESC* d3D12ResourceDesc, + DXGI_FORMAT dxgiFormat, + uint width, + uint height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes) { + D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height); ulong a, b; fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* p = &d3D12PlacedSubresourceFootprint) { uint _; - d3D12Device.GetCopyableFootprints(d3D12ResourceDesc, 0, 1, 0, p, &_, &a, &b); + d3D12Device.GetCopyableFootprints(&d3D12ResourceDescription, 0, 1, 0, p, &_, &a, &b); + } + + rowSizeInBytes = a; + totalSizeInBytes = b; + } + + /// + /// Gets the layout data for a target resource. + /// + /// The target to use to get the layout info. + /// The value to use. + /// The width of the texture resource. + /// The height of the texture resource. + /// The depth of the texture resource. + /// The resulting layout info for the resource. + /// The size in bytes of each row in the resource. + /// The total number of bytes for the resource. + public static void GetCopyableFootprint( + this ref ID3D12Device d3D12Device, + DXGI_FORMAT dxgiFormat, + uint width, + uint height, + ushort depth, + out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, + out ulong rowSizeInBytes, + out ulong totalSizeInBytes) + { + D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth); + ulong a, b; + + fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* p = &d3D12PlacedSubresourceFootprint) + { + uint _; + + d3D12Device.GetCopyableFootprints(&d3D12ResourceDescription, 0, 1, 0, p, &_, &a, &b); } rowSizeInBytes = a; diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs index fe45f36d..18c60bc1 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs @@ -145,10 +145,10 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -220,10 +220,10 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x)); Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)destination.Width, (uint)destination.Height); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)destination.Width, + (uint)destination.Height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -277,10 +277,10 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -347,10 +347,10 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x)); Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)source.Width, (uint)source.Height); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)source.Width, + (uint)source.Height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs index 240f0fcb..90432b64 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs @@ -159,10 +159,11 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z)); Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, + (ushort)depth, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -242,10 +243,11 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, + (ushort)depth, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -304,10 +306,11 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z)); Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, + (ushort)depth, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); @@ -382,10 +385,11 @@ namespace ComputeSharp.Resources Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y)); Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z)); - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, + (ushort)depth, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs index 26ca213a..a3a3ae28 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -57,10 +57,10 @@ namespace ComputeSharp.Resources Width = width; Height = height; - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs index aebbbede..c7a84fe0 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -60,10 +60,11 @@ namespace ComputeSharp.Resources Height = height; Depth = depth; - D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth); - GraphicsDevice.D3D12Device->GetCopyableFootprint( - &d3D12ResourceDescription, + DXGIFormatHelper.GetForType(), + (uint)width, + (uint)height, + (ushort)depth, out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint, out ulong rowSizeInBytes, out ulong totalSizeInBytes);