feat(renderer): integrate graphics pipeline and initialize gpu allocator with centralized frames in flight
This commit is contained in:
parent
c7fc5de690
commit
8af89292b6
|
|
@ -1,17 +1,21 @@
|
|||
mod device;
|
||||
pub mod error;
|
||||
mod instance;
|
||||
mod device;
|
||||
mod mesh;
|
||||
mod pipeline;
|
||||
mod renderer;
|
||||
mod surface;
|
||||
mod swapchain;
|
||||
mod sync;
|
||||
mod renderer;
|
||||
|
||||
use std::ffi::c_char;
|
||||
pub const MAX_FRAMES_IN_FLIGHT: usize = 3;
|
||||
|
||||
use ash::{Entry, vk};
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
||||
use std::ffi::c_char;
|
||||
|
||||
pub use error::RendererError;
|
||||
pub use renderer::{Renderer, MAX_FRAMES_IN_FLIGHT};
|
||||
pub use renderer::Renderer;
|
||||
|
||||
impl Renderer {
|
||||
/// Initializes the Vulkan renderer.
|
||||
|
|
@ -36,12 +40,15 @@ impl Renderer {
|
|||
surface::create_surface(&entry, &instance, display_handle, window_handle)?;
|
||||
|
||||
// 3. Physical Device (GPU)
|
||||
let physical_device =
|
||||
device::pick_physical_device(&instance, &surface_loader, surface)?;
|
||||
let physical_device = device::pick_physical_device(&instance, &surface_loader, surface)?;
|
||||
|
||||
// 4. Graphics Queue Index
|
||||
let graphics_queue_index =
|
||||
device::find_graphics_queue_family(&instance, physical_device, &surface_loader, surface)?;
|
||||
let graphics_queue_index = device::find_graphics_queue_family(
|
||||
&instance,
|
||||
physical_device,
|
||||
&surface_loader,
|
||||
surface,
|
||||
)?;
|
||||
|
||||
// 5. Logical Device and Queue
|
||||
let (device, graphics_queue) =
|
||||
|
|
@ -49,7 +56,15 @@ impl Renderer {
|
|||
|
||||
// 6. Swapchain
|
||||
let (swapchain_loader, swapchain, swapchain_images, swapchain_format, swapchain_extent) =
|
||||
swapchain::create_swapchain(&instance, physical_device, &device, &surface_loader, surface, width, height)?;
|
||||
swapchain::create_swapchain(
|
||||
&instance,
|
||||
physical_device,
|
||||
&device,
|
||||
&surface_loader,
|
||||
surface,
|
||||
width,
|
||||
height,
|
||||
)?;
|
||||
|
||||
// 7. Image Views
|
||||
let image_views =
|
||||
|
|
@ -71,7 +86,24 @@ impl Renderer {
|
|||
let command_buffers = unsafe { device.allocate_command_buffers(&alloc_info)? };
|
||||
|
||||
// 10. Synchronization Primitives
|
||||
let sync = sync::create_sync_primitives(&device, MAX_FRAMES_IN_FLIGHT, swapchain_images.len())?;
|
||||
let sync =
|
||||
sync::create_sync_primitives(&device, MAX_FRAMES_IN_FLIGHT, swapchain_images.len())?;
|
||||
|
||||
let allocator_create_info = gpu_allocator::vulkan::AllocatorCreateDesc {
|
||||
instance: instance.clone(),
|
||||
device: device.clone(),
|
||||
physical_device,
|
||||
debug_settings: Default::default(),
|
||||
buffer_device_address: false,
|
||||
allocation_sizes: Default::default(),
|
||||
};
|
||||
|
||||
let allocator = gpu_allocator::vulkan::Allocator::new(&allocator_create_info)
|
||||
.expect("Failed to create Vulkan allocator");
|
||||
|
||||
let pipeline_layout = pipeline::create_pipeline_layout(&device);
|
||||
let graphics_pipeline =
|
||||
pipeline::create_graphics_pipeline(&device, pipeline_layout, swapchain_format);
|
||||
|
||||
Ok(Self {
|
||||
_entry: entry,
|
||||
|
|
@ -92,6 +124,9 @@ impl Renderer {
|
|||
swapchain_image_views: image_views,
|
||||
command_pool,
|
||||
command_buffers,
|
||||
allocator,
|
||||
pipeline_layout,
|
||||
graphics_pipeline,
|
||||
sync,
|
||||
current_frame: 0,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::sync::SyncPrimitives;
|
|||
use ash::{Device, Instance, khr, vk};
|
||||
use gpu_allocator::vulkan::Allocator;
|
||||
|
||||
pub const MAX_FRAMES_IN_FLIGHT: usize = 3;
|
||||
|
||||
|
||||
/// The core renderer structure holding the Vulkan resources.
|
||||
pub struct Renderer {
|
||||
|
|
@ -51,7 +51,7 @@ pub struct Renderer {
|
|||
pub(crate) allocator: Allocator,
|
||||
/// Synchronization primitives for frame-by-frame execution.
|
||||
pub(crate) sync: SyncPrimitives,
|
||||
/// Index of the current frame being processed (0 to MAX_FRAMES_IN_FLIGHT - 1).
|
||||
/// Index of the current frame being processed (0 to crate::MAX_FRAMES_IN_FLIGHT - 1).
|
||||
pub(crate) current_frame: usize,
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ impl Renderer {
|
|||
}
|
||||
|
||||
// Advance the frame index for the next call
|
||||
self.current_frame = (self.current_frame + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
self.current_frame = (self.current_frame + 1) % crate::MAX_FRAMES_IN_FLIGHT;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue