From 4b08b7359d72784afcdf3e2b9b9c0e95bbe7e3cf Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Wed, 27 Nov 2024 21:27:50 +0100 Subject: [PATCH] vulkan: Move allocate to command pool --- src/renderer/mod.rs | 8 +++++++- src/renderer/vulkan/vk_command_pool.rs | 15 +++++++++++++++ src/renderer/vulkan/vk_render_context.rs | 12 ++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 8c19109..145c8fe 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -1 +1,7 @@ -pub mod vulkan; \ No newline at end of file +use ash::vk; + +pub mod vulkan; + +pub trait Renderable { + fn render(device: &vulkan::VkDevice, command_buffer: vk::CommandBuffer); +} \ No newline at end of file diff --git a/src/renderer/vulkan/vk_command_pool.rs b/src/renderer/vulkan/vk_command_pool.rs index b48b635..977f871 100644 --- a/src/renderer/vulkan/vk_command_pool.rs +++ b/src/renderer/vulkan/vk_command_pool.rs @@ -27,6 +27,21 @@ impl VkCommandPool { handle: command_pool, }) } + + pub fn allocate_command_buffers_for_framebuffers(&self, framebuffers_count: u32) -> VkResult> { + let command_buffer_info = vk::CommandBufferAllocateInfo::default() + .command_pool(self.handle) + .level(vk::CommandBufferLevel::PRIMARY) + .command_buffer_count(framebuffers_count); + + let command_buffers = unsafe { + self.device + .handle + .allocate_command_buffers(&command_buffer_info)? + }; + + Ok(command_buffers) + } } impl Drop for VkCommandPool { diff --git a/src/renderer/vulkan/vk_render_context.rs b/src/renderer/vulkan/vk_render_context.rs index f417809..55fb4e8 100644 --- a/src/renderer/vulkan/vk_render_context.rs +++ b/src/renderer/vulkan/vk_render_context.rs @@ -66,17 +66,9 @@ impl VkRenderContext { let command_pool = VkCommandPool::new(&device)?; - let command_buffer_info = vk::CommandBufferAllocateInfo::default() - .command_pool(command_pool.handle) - .level(vk::CommandBufferLevel::PRIMARY) - .command_buffer_count(framebuffers.len() as u32); - // Destroyed with command pool - let command_buffers = unsafe { - device - .handle - .allocate_command_buffers(&command_buffer_info)? - }; + let command_buffers = command_pool + .allocate_command_buffers_for_framebuffers(framebuffers.len() as u32)?; let image_available_semaphore = VkSemaphore::new(&device)?; let render_finished_semaphore = VkSemaphore::new(&device)?;