diff --git a/src/Graphics/ResourceInitializer.cs b/src/Graphics/ResourceInitializer.cs
index 4541154..cec8e69 100644
--- a/src/Graphics/ResourceInitializer.cs
+++ b/src/Graphics/ResourceInitializer.cs
@@ -181,6 +181,30 @@ namespace MoonWorks.Graphics
/// Uploads all the data corresponding to the created resources.
///
public void Upload()
+ {
+ CopyToTransferBuffer();
+
+ var commandBuffer = Device.AcquireCommandBuffer();
+ RecordUploadCommands(commandBuffer);
+ Device.Submit(commandBuffer);
+ }
+
+ ///
+ /// Uploads and then blocks until the upload is finished.
+ /// This is useful for keeping memory usage down during threaded upload.
+ ///
+ public void UploadAndWait()
+ {
+ CopyToTransferBuffer();
+
+ var commandBuffer = Device.AcquireCommandBuffer();
+ RecordUploadCommands(commandBuffer);
+ var fence = Device.SubmitAndAcquireFence(commandBuffer);
+ Device.WaitForFences(fence);
+ Device.ReleaseFence(fence);
+ }
+
+ private void CopyToTransferBuffer()
{
if (TransferBuffer == null || TransferBuffer.Size < dataSize)
{
@@ -190,9 +214,10 @@ namespace MoonWorks.Graphics
var dataSpan = new Span(data, (int) dataSize);
TransferBuffer.SetData(dataSpan, SetDataOptions.Discard);
+ }
- var commandBuffer = Device.AcquireCommandBuffer();
-
+ private void RecordUploadCommands(CommandBuffer commandBuffer)
+ {
commandBuffer.BeginCopyPass();
foreach (var (gpuBuffer, offset, size) in BufferUploads)
@@ -222,7 +247,6 @@ namespace MoonWorks.Graphics
}
commandBuffer.EndCopyPass();
- Device.Submit(commandBuffer);
BufferUploads.Clear();
TextureUploads.Clear();