Fixed Texture2D<T> memory copy APIs
このコミットが含まれているのは:
1 親
7fabac09ae
コミット
8851720749
2ファイル変更
+88
-9
検索条件に一致するファイルはありません
@@ -9,7 +9,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
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 pointer.
|
||||
/// </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>
|
||||
@@ -23,10 +23,10 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
}
|
||||
|
||||
/// <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 a pointer 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="source">The pointer 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>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -35,5 +35,77 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
new Span<T>((T*)source + sourceOffset, destination.Length).CopyTo(destination);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the content of a <see cref="ReadOnlySpan{T}"/> to the 2D area pointed by an input pointer.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to read.</typeparam>
|
||||
/// <param name="source">The destination <see cref="Span{T}"/> to read from.</param>
|
||||
/// <param name="destination">The pointer that indicates the 2D memory area to write to.</param>
|
||||
/// <param name="width">The width of the 2D memory area to read.</param>
|
||||
/// <param name="height">The height of the 2D memory area to read.</param>
|
||||
/// <param name="widthInBytes">The width of the memory area in bytes.</param>
|
||||
/// <param name="pitchInBytes">The pitch (padded width) of the memory area in bytes.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy<T>(
|
||||
ReadOnlySpan<T> source,
|
||||
void* destination,
|
||||
int width,
|
||||
int height,
|
||||
ulong widthInBytes,
|
||||
ulong pitchInBytes)
|
||||
where T : unmanaged
|
||||
{
|
||||
if (widthInBytes == pitchInBytes)
|
||||
{
|
||||
source.CopyTo(new Span<T>(destination, width * height));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
ReadOnlySpan<T> sourceRow = source.Slice(i * width, width);
|
||||
Span<T> destinationRow = new((byte*)destination + (uint)i * pitchInBytes, width);
|
||||
|
||||
sourceRow.CopyTo(destinationRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a 2D memory area pointed by a pointer value to a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to read.</typeparam>
|
||||
/// <param name="source">The pointer that indicates the memory area to read from.</param>
|
||||
/// <param name="width">The width of the 2D memory area to read.</param>
|
||||
/// <param name="height">The height of the 2D memory area to read.</param>
|
||||
/// <param name="widthInBytes">The width of the memory area in bytes.</param>
|
||||
/// <param name="pitchInBytes">The pitch (padded width) of the memory area in bytes.</param>
|
||||
/// <param name="destination">The destination <see cref="Span{T}"/> to write.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy<T>(
|
||||
void* source,
|
||||
int width,
|
||||
int height,
|
||||
ulong widthInBytes,
|
||||
ulong pitchInBytes,
|
||||
Span<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
if (widthInBytes == pitchInBytes)
|
||||
{
|
||||
new Span<T>(source, width * height).CopyTo(destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
ReadOnlySpan<T> sourceRow = new((byte*)source + (uint)i * pitchInBytes, width);
|
||||
Span<T> destinationRow = destination.Slice(i * width, width);
|
||||
|
||||
sourceRow.CopyTo(destinationRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする