destroy update

pull/17/head
cosmonaut 2022-03-03 17:16:39 -08:00
parent 42754ef80d
commit 17333cfb67
10 changed files with 9 additions and 33 deletions

@ -1 +1 @@
Subproject commit 1a9495366722c0334b563d6c7daa73bcc49d00eb Subproject commit 06466292d5e6dae3b73324c251c9484f1edeef09

View File

@ -135,8 +135,6 @@ namespace MoonWorks
Draw(timestep, alpha); Draw(timestep, alpha);
} }
GraphicsDevice.SubmitDestroyCommandBuffer();
} }
OnDestroy(); OnDestroy();

View File

@ -11,7 +11,6 @@ namespace MoonWorks.Graphics
public bool IsDisposed { get; private set; } public bool IsDisposed { get; private set; }
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>(); 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( public GraphicsDevice(
IntPtr deviceWindowHandle, IntPtr deviceWindowHandle,
@ -62,26 +61,6 @@ namespace MoonWorks.Graphics
return (TextureFormat) Refresh.Refresh_GetSwapchainFormat(Handle, window.Handle); 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) internal void AddResourceReference(WeakReference<GraphicsResource> resourceReference)
{ {
lock (resources) lock (resources)
@ -117,7 +96,6 @@ namespace MoonWorks.Graphics
resources.Clear(); resources.Clear();
} }
SubmitDestroyCommandBuffer();
Refresh.Refresh_DestroyDevice(Handle); Refresh.Refresh_DestroyDevice(Handle);
} }

View File

@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
public IntPtr Handle { get; protected set; } public IntPtr Handle { get; protected set; }
public bool IsDisposed { get; private 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; private WeakReference<GraphicsResource> selfReference;
@ -29,7 +29,7 @@ namespace MoonWorks.Graphics
{ {
if (selfReference != null) if (selfReference != null)
{ {
Device.PrepareDestroyResource(this, QueueDestroyFunction); QueueDestroyFunction(Device.Handle, Handle);
Device.RemoveResourceReference(selfReference); Device.RemoveResourceReference(selfReference);
selfReference = null; selfReference = null;
} }

View File

@ -9,7 +9,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public class Buffer : GraphicsResource public class Buffer : GraphicsResource
{ {
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer; protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
/// <summary> /// <summary>
/// Creates a buffer of appropriate size given a type and element count. /// Creates a buffer of appropriate size given a type and element count.

View File

@ -6,7 +6,7 @@ namespace MoonWorks.Graphics
{ {
public class ComputePipeline : GraphicsResource 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; } public ComputeShaderInfo ComputeShaderInfo { get; }

View File

@ -10,7 +10,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public class GraphicsPipeline : GraphicsResource 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 VertexShaderInfo { get; }
public GraphicsShaderInfo FragmentShaderInfo { get; } public GraphicsShaderInfo FragmentShaderInfo { get; }

View File

@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public class Sampler : GraphicsResource 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( public Sampler(
GraphicsDevice device, GraphicsDevice device,

View File

@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
public class ShaderModule : GraphicsResource 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) public unsafe ShaderModule(GraphicsDevice device, string filePath) : base(device)
{ {

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Graphics
public SampleCount SampleCount { get; } public SampleCount SampleCount { get; }
public TextureUsageFlags UsageFlags { 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> /// <summary>
/// Loads a PNG from a file path. /// Loads a PNG from a file path.