Minor code tweaks
このコミットが含まれているのは:
1 親
b42747f74d
コミット
f2229705dc
5ファイル変更
+27
-29
検索条件に一致するファイルはありません
@@ -61,7 +61,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// The pointer to the mapped resource.
|
||||
/// </summary>
|
||||
public readonly IntPtr Pointer;
|
||||
public readonly void* Pointer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MappedResource"/> instance for a given <see cref="ID3D12Resource"/> value.
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
|
||||
using MappedResource resource = transferBuffer.MapResource();
|
||||
|
||||
MemoryHelper.Copy(resource.Pointer, 0, span, 0, count);
|
||||
MemoryHelper.Copy(resource.Pointer, 0, span, count);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace ComputeSharp
|
||||
Unsafe.Add(ref spanRef, i) = Unsafe.As<byte, T>(ref targetRef);
|
||||
}
|
||||
}
|
||||
else MemoryHelper.Copy(resource.Pointer, offset, span, 0, count);
|
||||
else MemoryHelper.Copy(resource.Pointer, offset, span, count);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -15,13 +15,13 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <param name="d3d12resource">The target <see cref="ID3D12Resource"/> to map.</param>
|
||||
/// <returns>A pointer to the mapped area for <paramref name="d3d12resource"/>.</returns>
|
||||
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
|
||||
public static IntPtr Map(this ref ID3D12Resource d3d12resource)
|
||||
public static void* Map(this ref ID3D12Resource d3d12resource)
|
||||
{
|
||||
IntPtr ptr;
|
||||
void* pointer;
|
||||
|
||||
d3d12resource.Map(0, null, (void**)&ptr).Assert();
|
||||
d3d12resource.Map(0, null, &pointer).Assert();
|
||||
|
||||
return ptr;
|
||||
return pointer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,41 +4,39 @@ using System.Runtime.CompilerServices;
|
||||
namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with some helper methods to copy data between memory areas
|
||||
/// A <see langword="class"/> with some helper methods to copy data between memory areas.
|
||||
/// </summary>
|
||||
internal static class MemoryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Copies the content of a <see cref="ReadOnlySpan{T}"/> to the area pointed by an input <see cref="IntPtr"/> value
|
||||
/// Copies the content of a <see cref="ReadOnlySpan{T}"/> to the area pointed by an input <see cref="IntPtr"/> value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values in the input <see cref="ReadOnlySpan{T}"/></typeparam>
|
||||
/// <param name="source">The source <see cref="ReadOnlySpan{T}"/> to read</param>
|
||||
/// <param name="destination">The <see cref="IntPtr"/> for the destination memory area</param>
|
||||
/// <param name="destinationOffset">The destination offset to start writing data to</param>
|
||||
/// <param name="count">The total number of items to copy</param>
|
||||
/// <typeparam name="T">The type of values in the input <see cref="ReadOnlySpan{T}"/>.</typeparam>
|
||||
/// <param name="source">The source <see cref="ReadOnlySpan{T}"/> to read.</param>
|
||||
/// <param name="destination">The pointer for the destination memory area.</param>
|
||||
/// <param name="destinationOffset">The destination offset to start writing data to.</param>
|
||||
/// <param name="count">The total number of items to copy.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy<T>(ReadOnlySpan<T> source, IntPtr destination, int destinationOffset, int count) where T : unmanaged
|
||||
public static unsafe void Copy<T>(ReadOnlySpan<T> source, void* destination, int destinationOffset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
T* p = (T*)destination.ToPointer() + destinationOffset;
|
||||
|
||||
source.CopyTo(new Span<T>(p, count));
|
||||
source.CopyTo(new Span<T>((T*)destination + destinationOffset, count));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a memory area pointed by an <see cref="IntPtr"/> value to a target <see cref="Span{T}"/>
|
||||
/// Copies a memory area pointed by an <see cref="IntPtr"/> value to a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to read</typeparam>
|
||||
/// <param name="source">The <see cref="IntPtr"/> that indicates the memory area to read from</param>
|
||||
/// <param name="sourceOffset">The source offset to start reading data from</param>
|
||||
/// <param name="destination">The destination <see cref="Span{T}"/> to write</param>
|
||||
/// <param name="destinationOffset">The destination offset to start writing data to</param>
|
||||
/// <param name="count">The total number of items to copy</param>
|
||||
/// <typeparam name="T">The type of values to read.</typeparam>
|
||||
/// <param name="source">The <see cref="IntPtr"/> that indicates the memory area to read from.</param>
|
||||
/// <param name="sourceOffset">The source offset to start reading data from.</param>
|
||||
/// <param name="destination">The destination <see cref="Span{T}"/> to write.</param>
|
||||
/// <param name="destinationOffset">The destination offset to start writing data to.</param>
|
||||
/// <param name="count">The total number of items to copy.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy<T>(IntPtr source, int sourceOffset, Span<T> destination, int destinationOffset, int count) where T : unmanaged
|
||||
public static unsafe void Copy<T>(void* source, int sourceOffset, Span<T> destination, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
ref T rin = ref Unsafe.AsRef<T>(source.ToPointer());
|
||||
void* target = Unsafe.AsPointer(ref Unsafe.Add(ref rin, sourceOffset));
|
||||
new Span<T>(target, count).CopyTo(destination.Slice(destinationOffset, count));
|
||||
new Span<T>((T*)source + sourceOffset, count).CopyTo(destination.Slice(0, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする