move command pool to its own module

This commit is contained in:
jacekpoz 2024-09-24 12:03:16 +02:00
parent 495c2f458a
commit 88b2154c16
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 45 additions and 19 deletions

25
src/ptk_vk/command_pool.c Normal file
View file

@ -0,0 +1,25 @@
#include <ptk_vk/command_pool.h>
#include <ptk_vk/device.h>
#include <ptk_vk/utils.h>
PTK_OPTION(VkCommandPool) vk_create_command_pool(VkDevice dev) {
VkCommandPool ret;
VK_TRY(PTK_OPTION_NONE(VkCommandPool),
vkCreateCommandPool(
dev,
&(VkCommandPoolCreateInfo){
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = NULL,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = g_queue_family_indices.graphics.value,
},
NULL,
&ret
)
);
return PTK_OPTION_SOME(VkCommandPool, ret);
}

14
src/ptk_vk/command_pool.h Normal file
View file

@ -0,0 +1,14 @@
// Copyright (jacekpoz 2024). Licensed under the EUPL-1.2 or later.
#ifndef PTK_PTK_VK_COMMAND_POOL_H_
#define PTK_PTK_VK_COMMAND_POOL_H_
#include <vulkan/vulkan_core.h>
#include <ptk_option.h>
PTK_OPTION_DEFINE(VkCommandPool);
PTK_OPTION(VkCommandPool) vk_create_command_pool(VkDevice dev);
#endif // PTK_PTK_VK_COMMAND_POOL_H_

View file

@ -2,6 +2,7 @@
#include <ptk_vk/init.h>
#include <ptk_vk/command_pool.h>
#include <ptk_vk/components.h>
#include <ptk_vk/descriptor_set_layout.h>
#include <ptk_vk/device.h>
@ -78,24 +79,6 @@ static const PTK_ARRAY(constcharptr) m_validation_layers = PTK_ARRAY_NEW(constch
static const PTK_ARRAY(constcharptr) m_validation_layers = PTK_ARRAY_EMPTY(constcharptr);
#endif
bool create_command_pool(void) {
VK_TRY(false,
vkCreateCommandPool(
g_dev,
&(VkCommandPoolCreateInfo){
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = NULL,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = g_queue_family_indices.graphics.value,
},
NULL,
&m_command_pool
)
);
return true;
}
PTK_OPTION(uint32_t) find_memory_type(const uint32_t type_filter, const VkMemoryPropertyFlags props) {
VkPhysicalDeviceMemoryProperties mem_props;
vkGetPhysicalDeviceMemoryProperties(g_physical_dev, &mem_props);
@ -623,11 +606,15 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
return false;
}
if (!create_command_pool()) {
PTK_OPTION(VkCommandPool) command_pool_opt = vk_create_command_pool(g_dev);
if (!command_pool_opt.exists) {
PTK_ERR("failed creating command pool");
return false;
}
m_command_pool = command_pool_opt.value;
if (!create_vertex_buffer()) {
PTK_ERR("failed creating vertex buffer");
return false;