get rid of badly conceived command buffer queue

main
cosmonaut 2022-01-10 12:11:24 -08:00
parent 9df9aaeb3a
commit 1fe256a479
2 changed files with 4 additions and 28 deletions

View File

@ -9,16 +9,16 @@ namespace MoonWorks.Graphics
/// Command buffers are used to apply render state and issue draw calls.
/// NOTE: it is not recommended to hold references to command buffers long term.
/// </summary>
public class CommandBuffer
public struct CommandBuffer
{
public GraphicsDevice Device { get; }
public IntPtr Handle { get; internal set; }
// called from RefreshDevice
internal CommandBuffer(GraphicsDevice device)
internal CommandBuffer(GraphicsDevice device, IntPtr handle)
{
Device = device;
Handle = IntPtr.Zero;
Handle = handle;
}
/// <summary>

View File

@ -10,8 +10,6 @@ namespace MoonWorks.Graphics
public bool IsDisposed { get; private set; }
private readonly Queue<CommandBuffer> commandBufferPool;
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
public GraphicsDevice(
@ -30,26 +28,11 @@ namespace MoonWorks.Graphics
presentationParameters,
Conversions.BoolToByte(debugMode)
);
commandBufferPool = new Queue<CommandBuffer>(initialCommandBufferPoolSize);
for (var i = 0; i < initialCommandBufferPoolSize; i += 1)
{
commandBufferPool.Enqueue(new CommandBuffer(this));
}
}
public CommandBuffer AcquireCommandBuffer()
{
var commandBufferHandle = Refresh.Refresh_AcquireCommandBuffer(Handle, 0);
if (commandBufferPool.Count == 0)
{
commandBufferPool.Enqueue(new CommandBuffer(this));
}
var commandBuffer = commandBufferPool.Dequeue();
commandBuffer.Handle = commandBufferHandle;
return commandBuffer;
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
}
public unsafe void Submit(params CommandBuffer[] commandBuffers)
@ -66,13 +49,6 @@ namespace MoonWorks.Graphics
(uint) commandBuffers.Length,
(IntPtr) commandBufferPtrs
);
// return to pool
for (var i = 0; i < commandBuffers.Length; i += 1)
{
commandBuffers[i].Handle = IntPtr.Zero;
commandBufferPool.Enqueue(commandBuffers[i]);
}
}
public void Wait()