From e39fabf681bc82d9f55606e1f0f2bcfb139b3647 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 25 Sep 2024 19:59:18 +0200 Subject: [PATCH] clean up buffer.c from globals --- src/ptk_vk/buffer.c | 11 +++++------ src/ptk_vk/buffer.h | 2 +- src/ptk_vk/init.c | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ptk_vk/buffer.c b/src/ptk_vk/buffer.c index 20c0b9d..afc5555 100644 --- a/src/ptk_vk/buffer.c +++ b/src/ptk_vk/buffer.c @@ -2,7 +2,6 @@ #include -#include #include #include @@ -72,7 +71,7 @@ PTK_OPTION(BufferStuff) create_buffer(VkDevice dev, VkPhysicalDevice physical_de return PTK_OPTION_SOME(BufferStuff, ret); } -bool copy_buffer(VkDevice dev, VkCommandPool command_pool, const VkBuffer src, const VkBuffer dst, const VkDeviceSize size) { +bool copy_buffer(VkDevice dev, VkCommandPool command_pool, const VkBuffer src, const VkBuffer dst, const VkDeviceSize size, VkQueue graphics_queue) { VkCommandBuffer command_buffer; VK_TRY(false, @@ -109,7 +108,7 @@ bool copy_buffer(VkDevice dev, VkCommandPool command_pool, const VkBuffer src, c ); vkQueueSubmit( - /* TODO: get rid of this */g_graphics_queue, + graphics_queue, 1, &(VkSubmitInfo){ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, @@ -125,14 +124,14 @@ bool copy_buffer(VkDevice dev, VkCommandPool command_pool, const VkBuffer src, c VK_NULL_HANDLE ); - vkQueueWaitIdle(g_graphics_queue); + vkQueueWaitIdle(graphics_queue); vkFreeCommandBuffers(dev, command_pool, 1, &command_buffer); return true; } -bool transfer_to_buffer(VkDevice dev, VkPhysicalDevice physical_dev, VkCommandPool command_pool, void *src, size_t src_size, VkBuffer buffer) { +bool transfer_to_buffer(VkDevice dev, VkPhysicalDevice physical_dev, VkCommandPool command_pool, void *src, size_t src_size, VkBuffer buffer, VkQueue graphics_queue) { const VkDeviceSize buffer_size = src_size; PTK_OPTION(BufferStuff) staging_buffer_stuff_opt = create_buffer( @@ -156,7 +155,7 @@ bool transfer_to_buffer(VkDevice dev, VkPhysicalDevice physical_dev, VkCommandPo memcpy(data, src, (size_t)buffer_size); vkUnmapMemory(dev, staging_buffer_memory); - if (!copy_buffer(dev, command_pool, staging_buffer, buffer, buffer_size)) { + if (!copy_buffer(dev, command_pool, staging_buffer, buffer, buffer_size, graphics_queue)) { PTK_ERR("failed copying staging buffer to vertex buffer"); return false; } diff --git a/src/ptk_vk/buffer.h b/src/ptk_vk/buffer.h index aea8568..57d22d8 100644 --- a/src/ptk_vk/buffer.h +++ b/src/ptk_vk/buffer.h @@ -16,6 +16,6 @@ PTK_OPTION_DEFINE(BufferStuff); PTK_OPTION(BufferStuff) create_buffer(VkDevice dev, VkPhysicalDevice physical_dev, const VkDeviceSize size, const VkBufferUsageFlags usage, const VkMemoryPropertyFlags props); -bool transfer_to_buffer(VkDevice dev, VkPhysicalDevice physical_dev, VkCommandPool command_pool, void *src, size_t src_size, VkBuffer buffer); +bool transfer_to_buffer(VkDevice dev, VkPhysicalDevice physical_dev, VkCommandPool command_pool, void *src, size_t src_size, VkBuffer buffer, VkQueue graphics_queue); #endif // PTK_PTK_VK_BUFFER_H_ diff --git a/src/ptk_vk/init.c b/src/ptk_vk/init.c index 76cb954..00c1ccb 100644 --- a/src/ptk_vk/init.c +++ b/src/ptk_vk/init.c @@ -82,7 +82,7 @@ bool vk_transfer_vertex_data(void) { PTK_DEBUG("transferring vertices to gpu…"); const size_t vertices_size = sizeof(g_vertices.data[0]) * g_vertices.size; - if (!transfer_to_buffer(g_dev, g_physical_dev, m_command_pool, g_vertices.data, vertices_size, m_vertex_buffer)) { + if (!transfer_to_buffer(g_dev, g_physical_dev, m_command_pool, g_vertices.data, vertices_size, m_vertex_buffer, g_graphics_queue)) { PTK_ERR("failed transferring vertices"); return false; } @@ -94,7 +94,7 @@ bool vk_transfer_vertex_data(void) { PTK_DEBUG("transferring indices to gpu…"); const size_t indices_size = sizeof(g_indices.data[0]) * g_indices.size; - if (!transfer_to_buffer(g_dev, g_physical_dev, m_command_pool, g_indices.data, indices_size, m_index_buffer)) { + if (!transfer_to_buffer(g_dev, g_physical_dev, m_command_pool, g_indices.data, indices_size, m_index_buffer, g_graphics_queue)) { PTK_ERR("failed transferring indices"); return false; }