Code refactoring in MemoryHelper type

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-06 19:16:49 +01:00
1 親 111bcec623
コミット 0af9f32c61
5ファイル変更
+217 -135

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

+16 -3
ファイルの表示
@@ -52,8 +52,15 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
MemoryHelper.Copy(resource.Pointer, 0, destination);
fixed (void* destinationPointer = destination)
{
MemoryHelper.Copy(
resource.Pointer,
0u,
(uint)destination.Length,
(uint)sizeof(T),
destinationPointer);
}
}
/// <inheritdoc/>
@@ -73,8 +80,14 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = source)
{
MemoryHelper.Copy(source, resource.Pointer, 0);
MemoryHelper.Copy(
sourcePointer,
0u,
(uint)source.Length,
(uint)sizeof(T),
resource.Pointer);
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
+12 -10
ファイルの表示
@@ -274,13 +274,15 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
MemoryHelper.Copy(
resource.Pointer,
width,
height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
destination);
fixed (void* destinationPointer = destination)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
destinationPointer);
}
}
/// <summary>
@@ -415,12 +417,12 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = source)
{
MemoryHelper.Copy(
source,
sourcePointer,
resource.Pointer,
width,
height,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
+15 -13
ファイルの表示
@@ -269,15 +269,17 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
MemoryHelper.Copy(
resource.Pointer,
width,
height,
depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height,
destination);
fixed (void* destinationPointer = destination)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height,
destinationPointer);
}
}
/// <summary>
@@ -430,13 +432,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = source)
{
MemoryHelper.Copy(
source,
sourcePointer,
resource.Pointer,
width,
height,
depth,
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height);
+35 -30
ファイルの表示
@@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
@@ -64,24 +63,27 @@ namespace ComputeSharp
Guard.IsLessThanOrEqualTo((uint)offset + destination.Length, (uint)Length, nameof(destination));
using ID3D12ResourceMap resource = D3D12Resource->Map();
if (IsPaddingPresent)
fixed (void* destinationPointer = destination)
{
int count = destination.Length;
ref T spanRef = ref MemoryMarshal.GetReference(destination);
ref byte resourceRef = ref Unsafe.AsRef<byte>(resource.Pointer);
// Move to the initial ref
resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
for (var i = 0; i < count; i++)
if (IsPaddingPresent)
{
ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
Unsafe.Add(ref spanRef, i) = Unsafe.As<byte, T>(ref targetRef);
MemoryHelper.Copy<T>(
resource.Pointer,
(uint)offset,
(uint)destination.Length,
(uint)GetPaddedSize(),
destinationPointer);
}
else
{
MemoryHelper.Copy(
resource.Pointer,
(uint)offset,
(uint)destination.Length,
(uint)sizeof(T),
destinationPointer);
}
}
else MemoryHelper.Copy(resource.Pointer, offset, destination);
}
/// <inheritdoc/>
@@ -95,24 +97,27 @@ namespace ComputeSharp
Guard.IsLessThanOrEqualTo((uint)offset + source.Length, (uint)Length, nameof(source));
using ID3D12ResourceMap resource = D3D12Resource->Map();
if (IsPaddingPresent)
fixed (void* sourcePointer = source)
{
int count = source.Length;
ref T spanRef = ref MemoryMarshal.GetReference(source);
ref byte resourceRef = ref Unsafe.AsRef<byte>(resource.Pointer);
// Move to the initial offset
resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
for (var i = 0; i < count; i++)
if (IsPaddingPresent)
{
ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
Unsafe.As<byte, T>(ref targetRef) = Unsafe.Add(ref spanRef, i);
MemoryHelper.Copy<T>(
sourcePointer,
resource.Pointer,
(uint)offset,
(uint)source.Length,
(uint)GetPaddedSize());
}
else
{
MemoryHelper.Copy(
sourcePointer,
(uint)offset,
(uint)source.Length,
(uint)sizeof(T),
resource.Pointer);
}
}
else MemoryHelper.Copy(source, resource.Pointer, offset);
}
/// <inheritdoc/>
@@ -128,7 +133,7 @@ namespace ComputeSharp
source.GraphicsDevice == GraphicsDevice)
{
// Directly copy the input buffer, if possible
using CommandList copyCommandList = new CommandList(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();