From 17333cfb6782f4fd3572d7b518bd036177ab4319 Mon Sep 17 00:00:00 2001
From: cosmonaut <evan@moonside.games>
Date: Thu, 3 Mar 2022 17:16:39 -0800
Subject: [PATCH] destroy update

---
 lib/RefreshCS                              |  2 +-
 src/Game.cs                                |  2 --
 src/Graphics/GraphicsDevice.cs             | 22 ----------------------
 src/Graphics/GraphicsResource.cs           |  4 ++--
 src/Graphics/Resources/Buffer.cs           |  2 +-
 src/Graphics/Resources/ComputePipeline.cs  |  2 +-
 src/Graphics/Resources/GraphicsPipeline.cs |  2 +-
 src/Graphics/Resources/Sampler.cs          |  2 +-
 src/Graphics/Resources/ShaderModule.cs     |  2 +-
 src/Graphics/Resources/Texture.cs          |  2 +-
 10 files changed, 9 insertions(+), 33 deletions(-)

diff --git a/lib/RefreshCS b/lib/RefreshCS
index 1a949536..06466292 160000
--- a/lib/RefreshCS
+++ b/lib/RefreshCS
@@ -1 +1 @@
-Subproject commit 1a9495366722c0334b563d6c7daa73bcc49d00eb
+Subproject commit 06466292d5e6dae3b73324c251c9484f1edeef09
diff --git a/src/Game.cs b/src/Game.cs
index 4d9815b8..8078e3a0 100644
--- a/src/Game.cs
+++ b/src/Game.cs
@@ -135,8 +135,6 @@ namespace MoonWorks
 					Draw(timestep, alpha);
 
 				}
-
-				GraphicsDevice.SubmitDestroyCommandBuffer();
 			}
 
 			OnDestroy();
diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs
index e54f32ea..99915b47 100644
--- a/src/Graphics/GraphicsDevice.cs
+++ b/src/Graphics/GraphicsDevice.cs
@@ -11,7 +11,6 @@ namespace MoonWorks.Graphics
 		public bool IsDisposed { get; private set; }
 
 		private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
-		private Dictionary<IntPtr, Action<IntPtr, IntPtr, IntPtr>> resourcesToDestroy = new Dictionary<IntPtr, Action<IntPtr, IntPtr, IntPtr>>();
 
 		public GraphicsDevice(
 			IntPtr deviceWindowHandle,
@@ -62,26 +61,6 @@ namespace MoonWorks.Graphics
 			return (TextureFormat) Refresh.Refresh_GetSwapchainFormat(Handle, window.Handle);
 		}
 
-		internal void SubmitDestroyCommandBuffer()
-		{
-			if (resourcesToDestroy.Count > 0)
-			{
-				var commandBuffer = AcquireCommandBuffer();
-
-				foreach (var kv in resourcesToDestroy)
-				{
-					kv.Value.Invoke(Handle, commandBuffer.Handle, kv.Key);
-				}
-
-				Submit(commandBuffer);
-			}
-		}
-
-		internal void PrepareDestroyResource(GraphicsResource resource, Action<IntPtr, IntPtr, IntPtr> destroyFunction)
-		{
-			resourcesToDestroy.Add(resource.Handle, destroyFunction);
-		}
-
 		internal void AddResourceReference(WeakReference<GraphicsResource> resourceReference)
 		{
 			lock (resources)
@@ -117,7 +96,6 @@ namespace MoonWorks.Graphics
 						resources.Clear();
 					}
 
-					SubmitDestroyCommandBuffer();
 					Refresh.Refresh_DestroyDevice(Handle);
 				}
 
diff --git a/src/Graphics/GraphicsResource.cs b/src/Graphics/GraphicsResource.cs
index b1f73231..27343df3 100644
--- a/src/Graphics/GraphicsResource.cs
+++ b/src/Graphics/GraphicsResource.cs
@@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
 		public IntPtr Handle { get; protected set; }
 
 		public bool IsDisposed { get; private set; }
-		protected abstract Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction { get; }
+		protected abstract Action<IntPtr, IntPtr> QueueDestroyFunction { get; }
 
 		private WeakReference<GraphicsResource> selfReference;
 
@@ -29,7 +29,7 @@ namespace MoonWorks.Graphics
 			{
 				if (selfReference != null)
 				{
-					Device.PrepareDestroyResource(this, QueueDestroyFunction);
+					QueueDestroyFunction(Device.Handle, Handle);
 					Device.RemoveResourceReference(selfReference);
 					selfReference = null;
 				}
diff --git a/src/Graphics/Resources/Buffer.cs b/src/Graphics/Resources/Buffer.cs
index e8e56210..9af312fb 100644
--- a/src/Graphics/Resources/Buffer.cs
+++ b/src/Graphics/Resources/Buffer.cs
@@ -9,7 +9,7 @@ namespace MoonWorks.Graphics
 	/// </summary>
 	public class Buffer : GraphicsResource
 	{
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
 
 		/// <summary>
 		/// Creates a buffer of appropriate size given a type and element count.
diff --git a/src/Graphics/Resources/ComputePipeline.cs b/src/Graphics/Resources/ComputePipeline.cs
index 460871d9..f39d9a07 100644
--- a/src/Graphics/Resources/ComputePipeline.cs
+++ b/src/Graphics/Resources/ComputePipeline.cs
@@ -6,7 +6,7 @@ namespace MoonWorks.Graphics
 {
 	public class ComputePipeline : GraphicsResource
 	{
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;
 
 		public ComputeShaderInfo ComputeShaderInfo { get; }
 
diff --git a/src/Graphics/Resources/GraphicsPipeline.cs b/src/Graphics/Resources/GraphicsPipeline.cs
index 8583b485..101ec3b7 100644
--- a/src/Graphics/Resources/GraphicsPipeline.cs
+++ b/src/Graphics/Resources/GraphicsPipeline.cs
@@ -10,7 +10,7 @@ namespace MoonWorks.Graphics
 	/// </summary>
 	public class GraphicsPipeline : GraphicsResource
 	{
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyGraphicsPipeline;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyGraphicsPipeline;
 
 		public GraphicsShaderInfo VertexShaderInfo { get; }
 		public GraphicsShaderInfo FragmentShaderInfo { get; }
diff --git a/src/Graphics/Resources/Sampler.cs b/src/Graphics/Resources/Sampler.cs
index 9aa805b4..39463ad3 100644
--- a/src/Graphics/Resources/Sampler.cs
+++ b/src/Graphics/Resources/Sampler.cs
@@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
 	/// </summary>
 	public class Sampler : GraphicsResource
 	{
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroySampler;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroySampler;
 
 		public Sampler(
 			GraphicsDevice device,
diff --git a/src/Graphics/Resources/ShaderModule.cs b/src/Graphics/Resources/ShaderModule.cs
index 8699634f..d76037ba 100644
--- a/src/Graphics/Resources/ShaderModule.cs
+++ b/src/Graphics/Resources/ShaderModule.cs
@@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
 	/// </summary>
 	public class ShaderModule : GraphicsResource
 	{
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyShaderModule;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyShaderModule;
 
 		public unsafe ShaderModule(GraphicsDevice device, string filePath) : base(device)
 		{
diff --git a/src/Graphics/Resources/Texture.cs b/src/Graphics/Resources/Texture.cs
index 41e460f9..14b40da7 100644
--- a/src/Graphics/Resources/Texture.cs
+++ b/src/Graphics/Resources/Texture.cs
@@ -17,7 +17,7 @@ namespace MoonWorks.Graphics
 		public SampleCount SampleCount { get; }
 		public TextureUsageFlags UsageFlags { get; }
 
-		protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
+		protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
 
 		/// <summary>
 		/// Loads a PNG from a file path.