Fixed Texture2D<T> memory copy to/from buffers
このコミットが含まれているのは:
1 親
10636d169b
コミット
0e1a5bcbb9
2ファイル変更
+81
-33
検索条件に一致するファイルはありません
@@ -225,15 +225,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.HasSizeGreaterThanOrEqualTo(destination, width * height, nameof(destination));
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
|
||||
ResourceType.ReadBack,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height);
|
||||
nint byteSize = (nint)width * height * Unsafe.SizeOf<T>();
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
|
||||
{
|
||||
copyCommandList.CopyTextureRegion(D3D12Resource, x, y, width, height, d3D12Resource.Get(), 0u, 0u);
|
||||
copyCommandList.CopyTextureToBufferRegion(D3D12Resource, (uint)x, (uint)y, (uint)width, (uint)height, (uint)Unsafe.SizeOf<T>(), d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>());
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
@@ -359,11 +357,9 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.HasSizeGreaterThanOrEqualTo(source, width * height, nameof(source));
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
|
||||
ResourceType.Upload,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height);
|
||||
nint byteSize = (nint)width * height * Unsafe.SizeOf<T>();
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
{
|
||||
@@ -372,7 +368,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
|
||||
copyCommandList.CopyTextureRegion(d3D12Resource.Get(), 0, 0, width, height, D3D12Resource, (uint)x, (uint)y);
|
||||
copyCommandList.CopyBufferToTextureRegion(d3D12Resource.Get(), (uint)x, (uint)y, (uint)width, (uint)height, (uint)Unsafe.SizeOf<T>(), D3D12Resource, DXGIFormatHelper.GetForType<T>());
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Commands
|
||||
{
|
||||
@@ -92,32 +93,83 @@ namespace ComputeSharp.Graphics.Commands
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a texture memory region from one resource to another.
|
||||
/// Copies a texture memory region from one resource (a buffer) to another (a texture).
|
||||
/// </summary>
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> to read from.</param>
|
||||
/// <param name="sourceX">The horizontal offset within <paramref name="d3D12ResourceSource"/>.</param>
|
||||
/// <param name="sourceY">The vertical offset within <paramref name="d3D12ResourceSource"/>.</param>
|
||||
/// <param name="sourceWidth">The width of the memory region to copy.</param>
|
||||
/// <param name="sourceHeight">The height of the memory region to copy.</param>
|
||||
/// <param name="d3d12ResourceDestination">The destination <see cref="ID3D12Resource"/> to write to.</param>
|
||||
/// <param name="destinationX">The horizontal offset within <paramref name="d3d12ResourceDestination"/>.</param>
|
||||
/// <param name="destinationY">The vertical offset within <paramref name="d3d12ResourceDestination"/>.</param>
|
||||
public readonly void CopyTextureRegion(
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a buffer) to read 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="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="elementSizeInBytes">The size of each element to copy.</param>
|
||||
/// <param name="d3d12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a texture) to write to.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> parameter curreently in use by the texture.</param>
|
||||
public readonly void CopyBufferToTextureRegion(
|
||||
ID3D12Resource* d3D12ResourceSource,
|
||||
int sourceX,
|
||||
int sourceY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
uint x,
|
||||
uint y,
|
||||
uint width,
|
||||
uint height,
|
||||
uint elementSizeInBytes,
|
||||
ID3D12Resource* d3d12ResourceDestination,
|
||||
uint destinationX,
|
||||
uint destinationY)
|
||||
DXGI_FORMAT dxgiFormat)
|
||||
{
|
||||
D3D12_TEXTURE_COPY_LOCATION
|
||||
d3D12TextureCopyLocationSource = new(d3D12ResourceSource),
|
||||
d3D12TextureCopyLocationDestination = new(d3d12ResourceDestination);
|
||||
D3D12_BOX d3D12Box = new(sourceX, sourceY, sourceX + sourceWidth, sourceY + sourceHeight);
|
||||
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));
|
||||
|
||||
this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(&d3D12TextureCopyLocationDestination, destinationX, destinationY, 0, &d3D12TextureCopyLocationSource, &d3D12Box);
|
||||
D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
|
||||
d3D12PlacedSubresourceFootprint.Offset = 0;
|
||||
d3D12PlacedSubresourceFootprint.Footprint = d3D12SubresourceFootprint;
|
||||
|
||||
D3D12_TEXTURE_COPY_LOCATION
|
||||
d3D12TextureCopyLocationDestination = new(d3d12ResourceDestination, 0),
|
||||
d3D12TextureCopyLocationSource = new(d3D12ResourceSource, d3D12PlacedSubresourceFootprint);
|
||||
|
||||
this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, 0, &d3D12TextureCopyLocationSource, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a texture memory region from one resource (a texture) to another (a buffer).
|
||||
/// </summary>
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a texture) to read 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="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="elementSizeInBytes">The size of each element to copy.</param>
|
||||
/// <param name="d3d12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a buffer) to write to.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> parameter curreently in use by the texture.</param>
|
||||
public readonly void CopyTextureToBufferRegion(
|
||||
ID3D12Resource* d3D12ResourceSource,
|
||||
uint x,
|
||||
uint y,
|
||||
uint width,
|
||||
uint height,
|
||||
uint elementSizeInBytes,
|
||||
ID3D12Resource* d3d12ResourceDestination,
|
||||
DXGI_FORMAT dxgiFormat)
|
||||
{
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(&d3D12TextureCopyLocationDestination, 0, 0, 0, &d3D12TextureCopyLocationSource, &d3D12Box);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする