Code refactoring to texture copies

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-05 22:19:35 +01:00
1 親 3183771b66
コミット 7e9bd561ca
6ファイル変更
+271 -162

検索条件に一致するファイルはありません

+96 -36
ファイルの表示
@@ -8,42 +8,19 @@ namespace ComputeSharp.Graphics.Extensions
/// </summary>
internal static unsafe class ID3D12GraphicsCommandListExtensions
{
/// <summary>
/// Copies a texture memory region from one resource (a buffer) to another (a texture).
/// </summary>
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
/// <param name="d3D12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a texture) to write to.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="z">The depthwise offset in the destination texture.</param>
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a buffer) to read from.</param>
/// <param name="d3D12PlacedSubresourceFootprintSource">The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value describing <paramref name="d3D12ResourceSource"/>.</param>
public static void CopyTextureRegion(
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
ID3D12Resource* d3D12ResourceDestination,
uint x,
uint y,
ushort z,
ID3D12Resource* d3D12ResourceSource,
D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource)
{
D3D12_TEXTURE_COPY_LOCATION
d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0),
d3D12TextureCopyLocationSource = new(d3D12ResourceSource, in *d3D12PlacedSubresourceFootprintSource);
d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, z, &d3D12TextureCopyLocationSource, null);
}
/// <summary>
/// Copies a texture memory region from one resource (a texture) to another (a buffer).
/// </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="d3D12PlacedSubresourceFootprintDestination">The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value describing <paramref name="d3D12ResourceDestination"/>.</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="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="z">The depthwise offset in the source texture.</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>
@@ -51,20 +28,103 @@ namespace ComputeSharp.Graphics.Extensions
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
ID3D12Resource* d3D12ResourceDestination,
D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination,
uint destinationX,
uint destinationY,
ushort destinationZ,
ID3D12Resource* d3D12ResourceSource,
uint x,
uint y,
ushort z,
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, in *d3D12PlacedSubresourceFootprintDestination),
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>
/// Copies a texture memory region from one resource (a buffer) to another (a texture).
/// </summary>
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
/// <param name="d3D12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a texture) to write to.</param>
/// <param name="destinationX">The horizontal offset in the destination texture.</param>
/// <param name="destinationY">The vertical offset in the destination texture.</param>
/// <param name="destinationZ">The depthwise offset in the destination texture.</param>
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a buffer) to read from.</param>
/// <param name="d3D12PlacedSubresourceFootprintSource">The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value describing <paramref name="d3D12ResourceSource"/>.</param>
/// <param name="sourceX">The horizontal offset in the source buffer.</param>
/// <param name="sourceY">The vertical offset in the source buffer.</param>
/// <param name="sourceZ">The depthwise offset in the source buffer.</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,
D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource,
uint sourceX,
uint sourceY,
ushort sourceZ,
uint width,
uint height,
ushort depth)
{
D3D12_TEXTURE_COPY_LOCATION
d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, in *d3D12PlacedSubresourceFootprintDestination),
d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0);
D3D12_BOX d3D12Box = new((int)x, (int)y, z, (int)(x + width), (int)(y + height), z + depth);
d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0),
d3D12TextureCopyLocationSource = new(d3D12ResourceSource, in *d3D12PlacedSubresourceFootprintSource);
D3D12_BOX d3D12Box;
D3D12_BOX* pD3D12Box;
d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, 0, 0, 0, &d3D12TextureCopyLocationSource, &d3D12Box);
if (sourceX == 0 && sourceY == 0 && sourceZ == 0 &&
width == d3D12PlacedSubresourceFootprintSource->Footprint.Width &&
height == d3D12PlacedSubresourceFootprintSource->Footprint.Height &&
depth == d3D12PlacedSubresourceFootprintSource->Footprint.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>
+71 -50
ファイルの表示
@@ -51,6 +51,11 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType;
/// <summary>
/// The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> description for the current resource.
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters.
/// </summary>
@@ -89,6 +94,14 @@ namespace ComputeSharp.Resources
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
switch (resourceType)
@@ -149,7 +162,7 @@ namespace ComputeSharp.Resources
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
@@ -163,15 +176,18 @@ namespace ComputeSharp.Resources
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprint,
D3D12Resource,
(uint)x,
(uint)y,
0,
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)x,
sourceY: (uint)y,
sourceZ: 0,
(uint)width,
(uint)height,
1);
depth: 1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
@@ -189,7 +205,7 @@ namespace ComputeSharp.Resources
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
destinationPointer);
}
}
@@ -220,14 +236,6 @@ namespace ComputeSharp.Resources
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)destination.Width,
(uint)destination.Height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
@@ -235,16 +243,22 @@ namespace ComputeSharp.Resources
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
destination.D3D12Resource,
&d3D12PlacedSubresourceFootprint,
D3D12Resource,
(uint)x,
(uint)y,
0,
(uint)width,
(uint)height,
1);
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)x,
sourceY: (uint)y,
sourceZ: 0,
(uint)width,
(uint)height,
1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
@@ -281,7 +295,7 @@ namespace ComputeSharp.Resources
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
@@ -295,7 +309,7 @@ namespace ComputeSharp.Resources
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
@@ -306,12 +320,18 @@ namespace ComputeSharp.Resources
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
D3D12Resource,
(uint)x,
(uint)y,
0,
d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprint);
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)x,
destinationY: (uint)y,
destinationZ: 0,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
@@ -347,14 +367,6 @@ namespace ComputeSharp.Resources
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)source.Width,
(uint)source.Height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
@@ -362,13 +374,22 @@ namespace ComputeSharp.Resources
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
D3D12Resource,
(uint)x,
(uint)y,
0,
source.D3D12Resource,
&d3D12PlacedSubresourceFootprint);
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)x,
destinationY: (uint)y,
destinationZ: 0,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
+75 -55
ファイルの表示
@@ -51,6 +51,11 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType;
/// <summary>
/// The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> description for the current resource.
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// Creates a new <see cref="Texture3D{T}"/> instance with the specified parameters.
/// </summary>
@@ -93,6 +98,15 @@ namespace ComputeSharp.Resources
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
switch (resourceType)
@@ -164,7 +178,7 @@ namespace ComputeSharp.Resources
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
@@ -178,12 +192,15 @@ namespace ComputeSharp.Resources
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprint,
D3D12Resource,
(uint)x,
(uint)y,
(ushort)z,
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)x,
sourceY: (uint)y,
sourceZ: (ushort)z,
(uint)width,
(uint)height,
(ushort)depth);
@@ -205,8 +222,8 @@ namespace ComputeSharp.Resources
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch * (uint)height,
destinationPointer);
}
}
@@ -243,15 +260,6 @@ namespace ComputeSharp.Resources
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
@@ -259,16 +267,22 @@ namespace ComputeSharp.Resources
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
destination.D3D12Resource,
&d3D12PlacedSubresourceFootprint,
D3D12Resource,
(uint)x,
(uint)y,
(ushort)z,
(uint)width,
(uint)height,
(ushort)depth);
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)x,
sourceY: (uint)y,
sourceZ: (ushort)z,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
@@ -285,7 +299,7 @@ namespace ComputeSharp.Resources
/// <param name="size">The size of the memory area to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="z">The depthwise offseet in the destination texture.</param>
/// <param name="z">The depthwise offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
/// <param name="depth">The depth of the memory area to write to.</param>
@@ -311,7 +325,7 @@ namespace ComputeSharp.Resources
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
@@ -326,8 +340,8 @@ namespace ComputeSharp.Resources
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height);
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch * (uint)height);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
@@ -338,12 +352,18 @@ namespace ComputeSharp.Resources
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
D3D12Resource,
(uint)x,
(uint)y,
(ushort)z,
d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprint);
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)x,
destinationY: (uint)y,
destinationZ: (ushort)z,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
@@ -359,7 +379,7 @@ namespace ComputeSharp.Resources
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="z">The depthwise offseet in the destination texture.</param>
/// <param name="z">The depthwise offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
/// <param name="depth">The depth of the memory area to write to.</param>
@@ -385,15 +405,6 @@ namespace ComputeSharp.Resources
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
@@ -401,13 +412,22 @@ namespace ComputeSharp.Resources
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
D3D12Resource,
(uint)x,
(uint)y,
(ushort)z,
source.D3D12Resource,
&d3D12PlacedSubresourceFootprint);
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)x,
destinationY: (uint)y,
destinationZ: (ushort)z,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
+10 -6
ファイルの表示
@@ -29,9 +29,9 @@ namespace ComputeSharp.Resources
private readonly T* mappedData;
/// <summary>
/// The stride in bytes for each row within <see cref="mappedData"/>.
/// The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> description for the current resource.
/// </summary>
private readonly int strideInBytes;
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// Creates a new <see cref="TransferTexture2D{T}"/> instance with the specified parameters.
@@ -61,13 +61,12 @@ namespace ComputeSharp.Resources
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
this.d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.strideInBytes = (int)d3D12PlacedSubresourceFootprint.Footprint.RowPitch;
}
/// <summary>
@@ -90,6 +89,11 @@ namespace ComputeSharp.Resources
/// </summary>
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
/// <summary>
/// Gets the <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value for the current resource.
/// </summary>
internal ref readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT D3D12PlacedSubresourceFootprint => ref this.d3D12PlacedSubresourceFootprint;
/// <inheritdoc/>
public TextureView2D<T> View
{
@@ -98,7 +102,7 @@ namespace ComputeSharp.Resources
{
ThrowIfDisposed();
return new(this.mappedData, Height, Width, this.strideInBytes);
return new(this.mappedData, Height, Width, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
}
+10 -6
ファイルの表示
@@ -29,9 +29,9 @@ namespace ComputeSharp.Resources
private readonly T* mappedData;
/// <summary>
/// The stride in bytes for each row within <see cref="mappedData"/>.
/// The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> description for the current resource.
/// </summary>
private readonly int strideInBytes;
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// Creates a new <see cref="TransferTexture3D{T}"/> instance with the specified parameters.
@@ -65,13 +65,12 @@ namespace ComputeSharp.Resources
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
out ulong rowSizeInBytes,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.strideInBytes = (int)d3D12PlacedSubresourceFootprint.Footprint.RowPitch;
}
/// <summary>
@@ -98,6 +97,11 @@ namespace ComputeSharp.Resources
/// </summary>
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
/// <summary>
/// Gets the <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value for the current resource.
/// </summary>
internal ref readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT D3D12PlacedSubresourceFootprint => ref this.d3D12PlacedSubresourceFootprint;
/// <inheritdoc/>
public TextureView3D<T> View
{
@@ -106,7 +110,7 @@ namespace ComputeSharp.Resources
{
ThrowIfDisposed();
return new(this.mappedData, Height, Width, Depth, this.strideInBytes);
return new(this.mappedData, Height, Width, Depth, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
}
+9 -9
ファイルの表示
@@ -54,9 +54,9 @@ namespace ComputeSharp
private readonly int height;
/// <summary>
/// The stride of the specified 2D region.
/// The row pitch of the specified 2D region.
/// </summary>
private readonly int strideInBytes;
private readonly int pitchInBytes;
/// <summary>
/// Initializes a new instance of the <see cref="TextureView2D{T}"/> struct with the specified parameters.
@@ -64,13 +64,13 @@ namespace ComputeSharp
/// <param name="pointer">The pointer to the start of the memory area to map.</param>
/// <param name="width">The width of the 2D memory area to map.</param>
/// <param name="height">The height of the 2D memory area to map.</param>
/// <param name="strideInBytes">The stride in bytes of the 2D memory area to map.</param>
internal TextureView2D(T* pointer, int width, int height, int strideInBytes)
/// <param name="pitchInBytes">The row pitch in bytes of the 2D memory area to map.</param>
internal TextureView2D(T* pointer, int width, int height, int pitchInBytes)
{
this.pointer = pointer;
this.width = width;
this.height = height;
this.strideInBytes = strideInBytes;
this.pitchInBytes = pitchInBytes;
}
/// <summary>
@@ -134,7 +134,7 @@ namespace ComputeSharp
ThrowHelper.ThrowIndexOutOfRangeException();
}
return ref *((T*)((byte*)this.pointer + (y * this.strideInBytes)) + x);
return ref *((T*)((byte*)this.pointer + (y * this.pitchInBytes)) + x);
}
}
@@ -294,7 +294,7 @@ namespace ComputeSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T* DangerousGetAddressAndByteStride(out int strideInBytes)
{
strideInBytes = this.strideInBytes;
strideInBytes = this.pitchInBytes;
return this.pointer;
}
@@ -313,7 +313,7 @@ namespace ComputeSharp
ThrowHelper.ThrowArgumentOutOfRangeExceptionForRow();
}
return new((byte*)this.pointer + (y * this.strideInBytes), this.width);
return new((byte*)this.pointer + (y * this.pitchInBytes), this.width);
}
/// <summary>
@@ -323,7 +323,7 @@ namespace ComputeSharp
/// <returns>Whether or not <paramref name="span"/> was correctly assigned.</returns>
public bool TryGetSpan(out Span<T> span)
{
if (this.strideInBytes == this.width)
if (this.pitchInBytes == this.width)
{
span = new(this.pointer, Length);