diff --git a/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.c b/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.c new file mode 100644 index 0000000..c3d1d97 --- /dev/null +++ b/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.c @@ -0,0 +1,23 @@ +#include "vulkan_command_pool.h" +#include "output_device/vulkan_output_devices.h" + +gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info) { + commandPool->commandPool = malloc(sizeof(gnPlatformCommandPool)); + + VkCommandPoolCreateInfo poolInfo = { + .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, + .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, + .queueFamilyIndex = info.queueIndex + }; + + if (vkCreateCommandPool(device->outputDevice->device, &poolInfo, NULL, &commandPool->commandPool->commandPool) != VK_SUCCESS) { + return GN_FAILED_TO_CREATE_COMMAND_POOL; + } + + return GN_SUCCESS; +} + +void gnDestroyCommandPoolFn(struct gnCommandPool_t* commandPool) { + vkDestroyCommandPool(commandPool->device->outputDevice->device, commandPool->commandPool->commandPool, NULL); + free(commandPool->commandPool); +} diff --git a/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.h b/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.h new file mode 100644 index 0000000..dbe40a2 --- /dev/null +++ b/rendering_api/vulkan/src/commands/command_pool/vulkan_command_pool.h @@ -0,0 +1,7 @@ +#pragma once +#include +#include "core/command/command_pool/gryphn_command_pool.h" + +typedef struct gnPlatformCommandPool_t { + VkCommandPool commandPool; +} gnPlatformCommandPool; diff --git a/src/core/command/command_pool/gryphn_command_pool.c b/src/core/command/command_pool/gryphn_command_pool.c new file mode 100644 index 0000000..721e47a --- /dev/null +++ b/src/core/command/command_pool/gryphn_command_pool.c @@ -0,0 +1,11 @@ +#include "gryphn_command_pool.h" +#include "core/gryphn_platform_functions.h" + +gnReturnCode gnCreateCommandPool(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info) { + commandPool->device = device; + return device->deviceFunctions->_gnCreateCommandPool(commandPool, device, info); +} + +void gnDestroyCommandPool(struct gnCommandPool_t* commandPool) { + commandPool->device->deviceFunctions->_gnDestroyCommandPool(commandPool); +} diff --git a/src/core/command/command_pool/gryphn_command_pool.h b/src/core/command/command_pool/gryphn_command_pool.h new file mode 100644 index 0000000..8c102fa --- /dev/null +++ b/src/core/command/command_pool/gryphn_command_pool.h @@ -0,0 +1,15 @@ +#pragma once +#include "stdint.h" +#include + +typedef struct gnCommandPoolInfo_t { + uint32_t queueIndex; +} gnCommandPoolInfo; + +typedef struct gnCommandPool_t { + struct gnPlatformCommandPool_t* commandPool; + struct gnOutputDevice_t* device; +} gnCommandPool; + +gnReturnCode gnCreateCommandPool(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info); +void gnDestroyCommandPool(struct gnCommandPool_t* commandPool); diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index 538b35a..28bcdb9 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -11,6 +11,7 @@ #include "renderpass/gryphn_render_pass_descriptor.h" #include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" #include "framebuffer/gryphn_framebuffer.h" +#include "command/command_pool/gryphn_command_pool.h" typedef struct gnFunctions_t { gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info); @@ -66,4 +67,7 @@ typedef struct gnDeviceFunctions_t { gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t framebufferInfo); void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer); + + gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info); + void (*_gnDestroyCommandPool)(struct gnCommandPool_t* commandPool); } gnDeviceFunctions; diff --git a/src/core/instance/init/gryphn_init.c b/src/core/instance/init/gryphn_init.c index ed4e9a5..a138577 100644 --- a/src/core/instance/init/gryphn_init.c +++ b/src/core/instance/init/gryphn_init.c @@ -79,4 +79,6 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti gnLoadDLLFunction(lib, functions->_gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn"); gnLoadDLLFunction(lib, functions->_gnCreateFramebuffer, "gnCreateFramebufferFn"); gnLoadDLLFunction(lib, functions->_gnDestroyFramebuffer, "gnDestroyFramebufferFn"); + gnLoadDLLFunction(lib, functions->_gnCreateCommandPool, "gnCreateCommandPoolFn"); + gnLoadDLLFunction(lib, functions->_gnDestroyCommandPool, "gnDestroyCommandPoolFn"); } diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index faa96ee..b599a20 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -26,7 +26,8 @@ typedef enum gnReturnCode_t { GN_UNSUPPORTED_SHADER_MODULE, GN_UNKNOWN_SUBPASS, GN_FAILED_TO_CREATE_FRAMEBUFFER, - GN_DIVERGENT_RENDERPASS + GN_DIVERGENT_RENDERPASS, + GN_FAILED_TO_CREATE_COMMAND_POOL } gnReturnCode; typedef gnReturnCode gnErrorCode; @@ -58,5 +59,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_UNKNOWN_SUBPASS: return "GN_UNKNOWN_SUBPASS"; case GN_FAILED_TO_CREATE_FRAMEBUFFER: return "GN_FAILED_TO_CREATE_FRAMEBUFFER"; case GN_DIVERGENT_RENDERPASS: return "GN_DIVERGENT_RENDERPASS"; + case GN_FAILED_TO_CREATE_COMMAND_POOL: return "GN_FAILED_TO_CREATE_COMMAND_POOL"; } }