add element-wise buffer upload

what_if_no_video_threads
cosmonaut 2024-02-23 15:40:01 -08:00
parent b29341eca3
commit fe520dc9cc
1 changed files with 39 additions and 12 deletions

View File

@ -1938,10 +1938,10 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Uploads data from a CpuBuffer to a TextureSlice. /// Uploads data from a TransferBuffer to a TextureSlice.
/// This copy occurs on the GPU timeline. /// This copy occurs on the GPU timeline.
/// ///
/// Overwriting the contents of the CpuBuffer before the command buffer /// Overwriting the contents of the TransferBuffer before the command buffer
/// has finished execution will cause undefined behavior. /// has finished execution will cause undefined behavior.
/// ///
/// You MAY assume that the copy has finished for subsequent commands. /// You MAY assume that the copy has finished for subsequent commands.
@ -1982,10 +1982,10 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Uploads data from a CpuBuffer to a GpuBuffer. /// Uploads data from a TransferBuffer to a GpuBuffer.
/// This copy occurs on the GPU timeline. /// This copy occurs on the GPU timeline.
/// ///
/// Overwriting the contents of the CpuBuffer before the command buffer /// Overwriting the contents of the TransferBuffer before the command buffer
/// has finished execution will cause undefined behavior. /// has finished execution will cause undefined behavior.
/// ///
/// You MAY assume that the copy has finished for subsequent commands. /// You MAY assume that the copy has finished for subsequent commands.
@ -2012,7 +2012,7 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Copies the entire contents of a CpuBuffer to a GpuBuffer. /// Copies the entire contents of a TransferBuffer to a GpuBuffer.
/// </summary> /// </summary>
public void UploadToBuffer( public void UploadToBuffer(
TransferBuffer transferBuffer, TransferBuffer transferBuffer,
@ -2026,10 +2026,37 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Downloads data from a Texture to a CpuBuffer. /// Copies data element-wise into from a TransferBuffer to a GpuBuffer.
/// </summary>
public void UploadToBuffer<T>(
TransferBuffer transferBuffer,
GpuBuffer gpuBuffer,
uint sourceStartElement,
uint destinationStartElement,
uint numElements
) where T : unmanaged
{
var elementSize = Marshal.SizeOf<T>();
var dataLengthInBytes = (uint) (elementSize * numElements);
var srcOffsetInBytes = (uint) (elementSize * sourceStartElement);
var dstOffsetInBytes = (uint) (elementSize * destinationStartElement);
UploadToBuffer(
transferBuffer,
gpuBuffer,
new BufferCopy(
srcOffsetInBytes,
dstOffsetInBytes,
dataLengthInBytes
)
);
}
/// <summary>
/// Downloads data from a Texture to a TransferBuffer.
/// This copy occurs on the GPU timeline. /// This copy occurs on the GPU timeline.
/// ///
/// You MAY NOT assume that the data in the CpuBuffer is /// You MAY NOT assume that the data in the TransferBuffer is
/// fully copied until the command buffer has finished execution. /// fully copied until the command buffer has finished execution.
/// </summary> /// </summary>
public void DownloadFromTexture( public void DownloadFromTexture(
@ -2053,7 +2080,7 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Downloads the contents of a Texture with no mips into a CpuBuffer. /// Downloads the contents of a Texture with no mips into a TransferBuffer.
/// </summary> /// </summary>
public void DownloadFromTexture( public void DownloadFromTexture(
Texture texture, Texture texture,
@ -2067,10 +2094,10 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Downloads data from a GpuBuffer to a CpuBuffer. /// Downloads data from a GpuBuffer to a TransferBuffer.
/// This copy occurs on the GPU timeline. /// This copy occurs on the GPU timeline.
/// ///
/// You MAY NOT assume that the data in the CpuBuffer is /// You MAY NOT assume that the data in the TransferBuffer is
/// fully copied until the command buffer has finished execution. /// fully copied until the command buffer has finished execution.
/// </summary> /// </summary>
public void DownloadFromBuffer( public void DownloadFromBuffer(
@ -2094,10 +2121,10 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Downloads data from a GpuBuffer to a CpuBuffer. /// Downloads data from a GpuBuffer to a TransferBuffer.
/// This copy occurs on the GPU timeline. /// This copy occurs on the GPU timeline.
/// ///
/// You MAY NOT assume that the data in the CpuBuffer is /// You MAY NOT assume that the data in the TransferBuffer is
/// fully copied until the command buffer has finished execution. /// fully copied until the command buffer has finished execution.
/// </summary> /// </summary>
public void DownloadFromBuffer( public void DownloadFromBuffer(