From 1fe256a479a1ccf2b08c6114361d4a8da64e4372 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 10 Jan 2022 12:11:24 -0800 Subject: [PATCH] get rid of badly conceived command buffer queue --- src/Graphics/CommandBuffer.cs | 6 +++--- src/Graphics/GraphicsDevice.cs | 26 +------------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index ade8a06d..efe359c8 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -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. /// - 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; } /// diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index d0bfabfb..7890f7a9 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -10,8 +10,6 @@ namespace MoonWorks.Graphics public bool IsDisposed { get; private set; } - private readonly Queue commandBufferPool; - private readonly List> resources = new List>(); public GraphicsDevice( @@ -30,26 +28,11 @@ namespace MoonWorks.Graphics presentationParameters, Conversions.BoolToByte(debugMode) ); - - commandBufferPool = new Queue(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()