mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 15:13:34 +00:00
working on better command buffers management
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:50:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 17:51:46 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/17 20:10:45 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace mlx
|
||||
{
|
||||
_cmd_pool.init();
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_cmd_buffers[i].init(this);
|
||||
_cmd_buffers[i].init(CmdBuffer::kind::long_time, this);
|
||||
}
|
||||
|
||||
void CmdManager::beginRecord(int active_image_index)
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/15 19:57:49 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:46:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/17 20:10:25 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <algorithm>
|
||||
#include <renderer/command/single_time_cmd_manager.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -24,7 +25,7 @@ namespace mlx
|
||||
for(int i = 0; i < MIN_POOL_SIZE; i++)
|
||||
{
|
||||
_buffers.emplace_back();
|
||||
_buffers.back().init(&_pool);
|
||||
_buffers.back().init(CmdBuffer::kind::single_time, &_pool);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace mlx
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
_buffers.emplace_back().init(&_pool);
|
||||
_buffers.emplace_back().init(CmdBuffer::kind::single_time, &_pool);
|
||||
return _buffers.back();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:09:56 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/17 17:36:18 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include <renderer/command/vk_cmd_pool.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class CmdBuffer;
|
||||
|
||||
class SingleTimeCmdManager
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:51:03 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/17 20:01:46 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,16 +14,18 @@
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/command/cmd_manager.h>
|
||||
#include <renderer/core/vk_semaphore.h>
|
||||
#include <renderer/buffers/vk_buffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void CmdBuffer::init(CmdManager* manager)
|
||||
void CmdBuffer::init(kind type, CmdManager* manager)
|
||||
{
|
||||
init(&manager->getCmdPool());
|
||||
init(type, &manager->getCmdPool());
|
||||
}
|
||||
|
||||
void CmdBuffer::init(CmdPool* pool)
|
||||
void CmdBuffer::init(kind type, CmdPool* pool)
|
||||
{
|
||||
_type = type;
|
||||
_pool = pool;
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
@@ -58,6 +60,18 @@ namespace mlx
|
||||
_state = state::recording;
|
||||
}
|
||||
|
||||
void CmdBuffer::bindVertexBuffer(Buffer& buffer) const noexcept
|
||||
{
|
||||
if(!isRecording())
|
||||
{
|
||||
core::error::report(e_kind::warning, "Vulkan : trying to bind a vertex buffer to a non recording command buffer");
|
||||
return;
|
||||
}
|
||||
VkDeviceSize offset[] = { buffer.getOffset() };
|
||||
vkCmdBindVertexBuffers(_cmd_buffer, 0, 1, &buffer.get(), offset);
|
||||
buffer.recordedInCmdBuffer();
|
||||
}
|
||||
|
||||
void CmdBuffer::endRecord()
|
||||
{
|
||||
if(!isInit())
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:44:48 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/17 20:01:55 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class Buffer;
|
||||
class Image;
|
||||
|
||||
class CmdBuffer
|
||||
{
|
||||
public:
|
||||
@@ -31,9 +34,15 @@ namespace mlx
|
||||
submitted, // buffer has been submitted
|
||||
};
|
||||
|
||||
enum class kind
|
||||
{
|
||||
single_time = 0,
|
||||
long_time
|
||||
};
|
||||
|
||||
public:
|
||||
void init(class CmdManager* manager);
|
||||
void init(class CmdPool* pool);
|
||||
void init(kind type, class CmdManager* manager);
|
||||
void init(kind type, class CmdPool* pool);
|
||||
void destroy() noexcept;
|
||||
|
||||
void beginRecord(VkCommandBufferUsageFlags usage = 0);
|
||||
@@ -43,6 +52,12 @@ namespace mlx
|
||||
inline void reset() noexcept { vkResetCommandBuffer(_cmd_buffer, 0); }
|
||||
void endRecord();
|
||||
|
||||
void bindVertexBuffer(Buffer& buffer) const noexcept;
|
||||
void bindIndexBuffer(Buffer& buffer) const noexcept;
|
||||
void copyBuffer(Buffer& dst, Buffer& src) const noexcept;
|
||||
void copyBufferToImage(Buffer& buffer, Image& image) const noexcept;
|
||||
void copyImagetoBuffer(Image& image, Buffer& buffer) const noexcept;
|
||||
|
||||
inline bool isInit() const noexcept { return _state != state::uninit; }
|
||||
inline bool isReadyToBeUsed() const noexcept { return _state == state::ready; }
|
||||
inline bool isRecording() const noexcept { return _state == state::recording; }
|
||||
@@ -58,6 +73,7 @@ namespace mlx
|
||||
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
||||
class CmdPool* _pool = nullptr;
|
||||
state _state = state::uninit;
|
||||
kind _type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user