update pool

This commit is contained in:
ouczbs 2024-03-14 12:10:37 +08:00
parent 5e9b0bb305
commit df8e818ac5
4 changed files with 8 additions and 7 deletions

View File

@ -41,7 +41,7 @@ namespace zstd {
}; };
T acquire() { T acquire() {
if (m_tail == m_head) { if (m_tail == m_head) {
return std::move(newT()); return newT();
} }
int tail = m_tail % m_size; int tail = m_tail % m_size;
m_tail++; m_tail++;

View File

@ -6,9 +6,9 @@ namespace vulkanapi {
:mName(name) :mName(name)
,mDevice(device) ,mDevice(device)
,mQueue(queue) ,mQueue(queue)
,mCommandPool(CommandPool(device, queueFlags, queue.QueueFamilyIndex())) ,mCommandPool(device, queueFlags, queue.QueueFamilyIndex())
,mWork(CommandThreadWorker(name, 64)) ,mWork(name, 64)
,mImmediateExeCmd(CommandBuffer(mCommandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)) ,mImmediateExeCmd(mCommandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)
{ {
} }
@ -22,6 +22,7 @@ namespace vulkanapi {
mWork.Invoke([=]() { mWork.Invoke([=]() {
CommandBuffer cmd = mCommandPool.Pop(); CommandBuffer cmd = mCommandPool.Pop();
Buffer(cmd, fn, callback); Buffer(cmd, fn, callback);
mCommandPool.Push(cmd);
}); });
} }
@ -32,7 +33,6 @@ namespace vulkanapi {
cmd.EndRecord(); cmd.EndRecord();
cmd.Submit(mQueue.Ptr()); cmd.Submit(mQueue.Ptr());
cmd.WaitFofFence(mDevice.Ptr()); cmd.WaitFofFence(mDevice.Ptr());
mCommandPool.Push(cmd);
callback(); callback();
} }

View File

@ -11,6 +11,7 @@ namespace vulkanapi {
public: public:
CommandBuffer(CommandPool& commandPool, VkCommandBufferLevel level); CommandBuffer(CommandPool& commandPool, VkCommandBufferLevel level);
~CommandBuffer(); ~CommandBuffer();
CommandBuffer(CommandBuffer* other)noexcept:CommandBuffer(std::forward<CommandBuffer>(*other)) {};
CommandBuffer(CommandBuffer&& other)noexcept; CommandBuffer(CommandBuffer&& other)noexcept;
VkCommandBuffer& Ptr() { VkCommandBuffer& Ptr() {
return mPtr; return mPtr;

View File

@ -23,11 +23,11 @@ namespace vulkanapi {
}; };
CommandBuffer Pop() CommandBuffer Pop()
{ {
return std::move(mPool.acquire()); return mPool.acquire();
} }
void Push(CommandBuffer& cmd) void Push(CommandBuffer& cmd)
{ {
mPool.release(std::forward<CommandBuffer>(cmd)); mPool.release(&cmd);
} }
}; };
} }