diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs
index 15e2d11e..0ccdafc6 100644
--- a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs
@@ -29,6 +29,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using (CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy))
{
copyCommandList.CopyBufferRegion(this, offset * ElementSizeInBytes, transferBuffer, 0, count * ElementSizeInBytes);
+ copyCommandList.ExecuteAndWaitForCompletion();
}
using MappedResource resource = transferBuffer.MapResource();
@@ -49,6 +50,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(transferBuffer, 0, this, offset * ElementSizeInBytes, count * ElementSizeInBytes);
+ copyCommandList.ExecuteAndWaitForCompletion();
}
///
@@ -60,6 +62,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes);
+ copyCommandList.ExecuteAndWaitForCompletion();
}
else SetDataWithCpuBuffer(buffer);
}
diff --git a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
index 186a3154..57fe2430 100644
--- a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
@@ -99,6 +99,7 @@ namespace ComputeSharp
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes);
+ copyCommandList.ExecuteAndWaitForCompletion();
}
else SetDataWithCpuBuffer(buffer);
}
diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs
index 8ae8c766..d344b2cf 100644
--- a/src/ComputeSharp.Graphics/Commands/CommandList.cs
+++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs
@@ -88,7 +88,7 @@ namespace ComputeSharp.Graphics.Commands
}
///
- /// Executes the pending command list using the specified thread group values
+ /// Dispatches the pending shader using the specified thread group values
///
/// The number of thread groups to schedule for the X axis
/// The number of thread groups to schedule for the Y axis
@@ -98,13 +98,19 @@ namespace ComputeSharp.Graphics.Commands
NativeCommandList.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
}
- ///
- public override void Dispose()
+ ///
+ /// Executes the commands in the current commands list, and waits for completion
+ ///
+ public void ExecuteAndWaitForCompletion()
{
NativeCommandList.Close();
GraphicsDevice.ExecuteCommandList(this);
+ }
+ ///
+ public override void Dispose()
+ {
switch (CommandListType)
{
case CommandListType.Direct:
diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
index eba0bbb6..488256e3 100644
--- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
+++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
@@ -125,6 +125,7 @@ namespace ComputeSharp.Shaders
// Dispatch and wait for completion
commandList.Dispatch(groupsX, groupsY, groupsZ);
+ commandList.ExecuteAndWaitForCompletion();
}
}
}