clean up buffer.c from globals

This commit is contained in:
jacekpoz 2024-09-25 19:59:18 +02:00
parent 2f0c678d89
commit e39fabf681
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 8 additions and 9 deletions

View file

@ -2,7 +2,6 @@
#include <ptk_vk/buffer.h>
#include <ptk_vk/init.h>
#include <ptk_vk/utils.h>
#include <string.h>
@ -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;
}

View file

@ -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_

View file

@ -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;
}