diff --git a/main.cpp b/main.cpp index 98d66dd..5ec9cf8 100644 --- a/main.cpp +++ b/main.cpp @@ -70,6 +70,7 @@ typedef Vertex *VertexArray; typedef ShaderDataBuffer *ShaderDataBufferArray; typedef VkFence *VkFenceArray; typedef VkSemaphore *VkSemaphoreArray; +typedef VkCommandBuffer *VkCommandBufferArray; wapp_intern inline void check(VkResult result); wapp_intern inline void check_swapchain(VkResult result); @@ -109,6 +110,8 @@ wapp_intern ShaderDataBufferArray shader_data_bufs; wapp_intern VkFenceArray fences; wapp_intern VkSemaphoreArray image_acquired_semaphores; wapp_intern VkSemaphoreArray render_completed_semaphores = nullptr; +wapp_intern VkCommandPool command_pool = VK_NULL_HANDLE; +wapp_intern VkCommandBufferArray command_buffers; int main() { // {{{ Initialisation @@ -569,8 +572,20 @@ int main() { } // }}} - // Command Pool {{{ + // Command Pool & Buffers {{{ + VkCommandPoolCreateInfo pool_create_info = {}; + pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + pool_create_info.queueFamilyIndex = queue_family_index; + check(vkCreateCommandPool(device, &pool_create_info, NULL, &command_pool)); + command_buffers = wapp_array_with_capacity(VkCommandBuffer, max_frames_in_flight, ARRAY_INIT_FILLED); + + VkCommandBufferAllocateInfo buffer_alloc_info = {}; + buffer_alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + buffer_alloc_info.commandPool = command_pool; + buffer_alloc_info.commandBufferCount = max_frames_in_flight; + check(vkAllocateCommandBuffers(device, &buffer_alloc_info, command_buffers)); // }}} // {{{ Render Loop @@ -592,6 +607,8 @@ int main() { // }}} // {{{ Cleanup + vkFreeCommandBuffers(device, command_pool, max_frames_in_flight, command_buffers); + vkDestroyCommandPool(device, command_pool, NULL); for (u32 i = 0; i < swapchain_image_count; ++i) { vkDestroySemaphore(device, render_completed_semaphores[i], NULL); }