move command buffer allocation to separate module
This commit is contained in:
parent
952d68f68f
commit
15e74a9a17
4 changed files with 49 additions and 23 deletions
25
src/ptk_vk/command_buffers.c
Normal file
25
src/ptk_vk/command_buffers.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <ptk_vk/command_buffers.h>
|
||||
|
||||
#include <ptk_vk/init.h>
|
||||
#include <ptk_vk/utils.h>
|
||||
|
||||
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool) {
|
||||
VkCommandBufferList ret = PTK_LIST_NEW(VkCommandBuffer, g_max_frames_in_flight);
|
||||
|
||||
VK_TRY(PTK_OPTION_NONE(VkCommandBufferList),
|
||||
vkAllocateCommandBuffers(
|
||||
dev,
|
||||
&(VkCommandBufferAllocateInfo){
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.pNext = NULL,
|
||||
.commandPool = command_pool,
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = ret.allocated,
|
||||
},
|
||||
ret.data
|
||||
)
|
||||
);
|
||||
PTK_LIST_FILLED(ret);
|
||||
|
||||
return PTK_OPTION_SOME(VkCommandBufferList, ret);
|
||||
}
|
17
src/ptk_vk/command_buffers.h
Normal file
17
src/ptk_vk/command_buffers.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (jacekpoz 2024). Licensed under the EUPL-1.2 or later.
|
||||
|
||||
#ifndef PTK_PTK_VK_COMMAND_BUFFERS_H_
|
||||
#define PTK_PTK_VK_COMMAND_BUFFERS_H_
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <ptk_list.h>
|
||||
#include <ptk_option.h>
|
||||
|
||||
PTK_LIST_DEFINE(VkCommandBuffer);
|
||||
typedef PTK_LIST(VkCommandBuffer) VkCommandBufferList;
|
||||
PTK_OPTION_DEFINE(VkCommandBufferList);
|
||||
|
||||
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool);
|
||||
|
||||
#endif // PTK_PTK_VK_COMMAND_BUFFERS_H_
|
|
@ -100,27 +100,6 @@ bool vk_transfer_vertex_data(void) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool allocate_command_buffers(void) {
|
||||
g_command_buffers = PTK_LIST_NEW(VkCommandBuffer, g_max_frames_in_flight);
|
||||
|
||||
VK_TRY(false,
|
||||
vkAllocateCommandBuffers(
|
||||
g_dev,
|
||||
&(VkCommandBufferAllocateInfo){
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.pNext = NULL,
|
||||
.commandPool = m_command_pool,
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = g_command_buffers.allocated,
|
||||
},
|
||||
g_command_buffers.data
|
||||
)
|
||||
);
|
||||
PTK_LIST_FILLED(g_command_buffers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vk_record_command_buffer(const VkCommandBuffer command_buffer, const uint32_t image_index) {
|
||||
VK_TRY(false,
|
||||
vkBeginCommandBuffer(
|
||||
|
@ -375,11 +354,15 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
|
|||
|
||||
m_descriptor_sets = descriptor_sets_opt.value;
|
||||
|
||||
if (!allocate_command_buffers()) {
|
||||
PTK_OPTION(VkCommandBufferList) command_buffers_opt = vk_allocate_command_buffers(g_dev, m_command_pool);
|
||||
|
||||
if (!command_buffers_opt.exists) {
|
||||
PTK_ERR("failed allocating command buffers");
|
||||
return false;
|
||||
}
|
||||
|
||||
g_command_buffers = command_buffers_opt.value;
|
||||
|
||||
if (!create_sync_objects()) {
|
||||
PTK_ERR("failed creating sync objects");
|
||||
return false;
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include <ptk.h>
|
||||
#include <ptk_list.h>
|
||||
|
||||
PTK_LIST_DEFINE(VkCommandBuffer);
|
||||
#include <ptk_vk/command_buffers.h>
|
||||
|
||||
PTK_LIST_DEFINE(VkSemaphore);
|
||||
PTK_LIST_DEFINE(VkFence);
|
||||
|
||||
|
|
Loading…
Reference in a new issue