feat(renderer): create command pool and buffer
This commit is contained in:
parent
65b43651bb
commit
d0fa203743
|
|
@ -41,6 +41,10 @@ pub struct Renderer {
|
||||||
swapchain_extent: vk::Extent2D,
|
swapchain_extent: vk::Extent2D,
|
||||||
/// The views into the swapchain images.
|
/// The views into the swapchain images.
|
||||||
swapchain_image_views: Vec<vk::ImageView>,
|
swapchain_image_views: Vec<vk::ImageView>,
|
||||||
|
/// The pool used to allocate command buffers.
|
||||||
|
command_pool: vk::CommandPool,
|
||||||
|
/// The buffer used to record GPU commands.
|
||||||
|
command_buffer: vk::CommandBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
|
|
@ -128,6 +132,22 @@ impl Renderer {
|
||||||
// Create image views for the swapchain images
|
// Create image views for the swapchain images
|
||||||
let image_views = Self::create_image_views(&device, &swapchain_images, swapchain_format)?;
|
let image_views = Self::create_image_views(&device, &swapchain_images, swapchain_format)?;
|
||||||
|
|
||||||
|
// Create the command pool
|
||||||
|
let pool_create_info = vk::CommandPoolCreateInfo::default()
|
||||||
|
.queue_family_index(graphics_queue_index)
|
||||||
|
// Allows us to reuse the command buffer every frame by resetting it
|
||||||
|
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER);
|
||||||
|
|
||||||
|
let command_pool = unsafe { device.create_command_pool(&pool_create_info, None)? };
|
||||||
|
|
||||||
|
// Allocate the main command buffer used for rendering
|
||||||
|
let alloc_info = vk::CommandBufferAllocateInfo::default()
|
||||||
|
.command_pool(command_pool)
|
||||||
|
.level(vk::CommandBufferLevel::PRIMARY)
|
||||||
|
.command_buffer_count(1);
|
||||||
|
|
||||||
|
let command_buffer = unsafe { device.allocate_command_buffers(&alloc_info)?[0] };
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_entry: entry,
|
_entry: entry,
|
||||||
instance,
|
instance,
|
||||||
|
|
@ -145,6 +165,8 @@ impl Renderer {
|
||||||
swapchain_format,
|
swapchain_format,
|
||||||
swapchain_extent,
|
swapchain_extent,
|
||||||
swapchain_image_views: image_views,
|
swapchain_image_views: image_views,
|
||||||
|
command_pool,
|
||||||
|
command_buffer,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,6 +377,8 @@ impl Renderer {
|
||||||
impl Drop for Renderer {
|
impl Drop for Renderer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
self.device.destroy_command_pool(self.command_pool, None);
|
||||||
|
|
||||||
// Destroy the swapchain
|
// Destroy the swapchain
|
||||||
self.swapchain_loader.destroy_swapchain(self.swapchain, None);
|
self.swapchain_loader.destroy_swapchain(self.swapchain, None);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue