vulkan: Move allocate to command pool
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s

This commit is contained in:
Florian RICHER 2024-11-27 21:27:50 +01:00
parent a669247406
commit 4b08b7359d
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
3 changed files with 24 additions and 11 deletions

View file

@ -1 +1,7 @@
pub mod vulkan;
use ash::vk;
pub mod vulkan;
pub trait Renderable {
fn render(device: &vulkan::VkDevice, command_buffer: vk::CommandBuffer);
}

View file

@ -27,6 +27,21 @@ impl VkCommandPool {
handle: command_pool,
})
}
pub fn allocate_command_buffers_for_framebuffers(&self, framebuffers_count: u32) -> VkResult<Vec<vk::CommandBuffer>> {
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 {

View file

@ -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)?;