/// <summary>
    /// Reads the contents of an <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="UploadBuffer{T}"/> instance.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the buffer.</typeparam>
    /// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
    /// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
    /// <param name="sourceOffset">The offset to start reading data from.</param>
    /// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
    /// <param name="count">The number of items to read.</param>
    public static void CopyFrom <T>(this StructuredBuffer <T> destination, UploadBuffer <T> source, int sourceOffset, int destinationOffset, int count)
        where T : unmanaged
    {
        Guard.IsNotNull(destination);
        Guard.IsNotNull(source);

        source.CopyTo(destination, sourceOffset, destinationOffset, count);
    }
    /// <summary>
    /// Reads the contents of an <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="UploadBuffer{T}"/> instance.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the buffer.</typeparam>
    /// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
    /// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
    public static void CopyFrom <T>(this StructuredBuffer <T> destination, UploadBuffer <T> source)
        where T : unmanaged
    {
        Guard.IsNotNull(destination);
        Guard.IsNotNull(source);

        source.CopyTo(destination, 0, 0, source.Length);
    }
Exemplo n.º 3
0
        public void Allocate_UploadBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
        {
            using UploadBuffer <int> uploadBuffer = device.Get().AllocateUploadBuffer <int>(4096);

            new Random(42).NextBytes(uploadBuffer.Span.AsBytes());

            using ReadOnlyBuffer <int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer <int>(uploadBuffer.Length);

            uploadBuffer.CopyTo(readOnlyBuffer, destinationOffset, bufferOffset, count);

            int[] result = readOnlyBuffer.ToArray(destinationOffset, count);

            Assert.AreEqual(result.Length, count);
            Assert.IsTrue(uploadBuffer.Span.Slice(bufferOffset, count).SequenceEqual(result));
        }
Exemplo n.º 4
0
        public void Allocate_UploadBuffer_Copy_Full(Device device)
        {
            using UploadBuffer <int> uploadBuffer = device.Get().AllocateUploadBuffer <int>(4096);

            new Random(42).NextBytes(uploadBuffer.Span.AsBytes());

            using ReadOnlyBuffer <int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer <int>(uploadBuffer.Length);

            uploadBuffer.CopyTo(readOnlyBuffer);

            int[] result = readOnlyBuffer.ToArray();

            Assert.AreEqual(uploadBuffer.Length, result.Length);
            Assert.IsTrue(uploadBuffer.Span.SequenceEqual(result));
        }