destroy update

main
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);
}
GraphicsDevice.SubmitDestroyCommandBuffer();
}
OnDestroy();

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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; }

View File

@ -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; }

View File

@ -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,

View File

@ -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)
{

View File

@ -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.