diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs
index 63252662..a2327892 100644
--- a/src/ComputeSharp.Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs
@@ -126,6 +126,11 @@ namespace ComputeSharp.Graphics
///
internal ID3D12Fence NativeDirectFence { get; }
+ ///
+ /// The used to lock command list executions
+ ///
+ private readonly object Lock = new object();
+
///
/// Gets the next fence value for compute operations
///
@@ -169,7 +174,7 @@ namespace ComputeSharp.Graphics
if (fenceValue <= fence.CompletedValue) return;
- lock (fence)
+ lock (Lock)
{
fence.SetEventOnCompletion(fenceValue, AutoResetEvent.SafeWaitHandle.DangerousGetHandle());
AutoResetEvent.WaitOne();
@@ -194,25 +199,19 @@ namespace ComputeSharp.Graphics
commandAllocatorPool = ComputeAllocatorPool;
commandQueue = NativeComputeCommandQueue;
fence = NativeComputeFence;
- fenceValue = NextComputeFenceValue;
-
- NextComputeFenceValue++;
+ fenceValue = NextComputeFenceValue++;
break;
case CommandListType.Copy:
commandAllocatorPool = CopyAllocatorPool;
commandQueue = NativeCopyCommandQueue;
fence = NativeCopyFence;
- fenceValue = NextCopyFenceValue;
-
- NextCopyFenceValue++;
+ fenceValue = NextCopyFenceValue++;
break;
case CommandListType.Direct:
commandAllocatorPool = DirectAllocatorPool;
commandQueue = NativeDirectCommandQueue;
fence = NativeDirectFence;
- fenceValue = NextDirectFenceValue;
-
- NextDirectFenceValue++;
+ fenceValue = NextDirectFenceValue++;
break;
default: throw new NotSupportedException($"Unsupported command list of type {commandList.CommandListType}");
}