get rid of badly conceived command buffer queue

pull/14/head
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. /// 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. /// NOTE: it is not recommended to hold references to command buffers long term.
/// </summary> /// </summary>
public class CommandBuffer public struct CommandBuffer
{ {
public GraphicsDevice Device { get; } public GraphicsDevice Device { get; }
public IntPtr Handle { get; internal set; } public IntPtr Handle { get; internal set; }
// called from RefreshDevice // called from RefreshDevice
internal CommandBuffer(GraphicsDevice device) internal CommandBuffer(GraphicsDevice device, IntPtr handle)
{ {
Device = device; Device = device;
Handle = IntPtr.Zero; Handle = handle;
} }
/// <summary> /// <summary>

View File

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