2022-03-06 19:30:49 +00:00
|
|
|
use crate::{
|
2022-06-24 15:27:33 +00:00
|
|
|
game_of_life::GameOfLifeComputePipeline, render_pass::RenderPassPlaceOverFrame, SCALING,
|
|
|
|
WINDOW2_HEIGHT, WINDOW2_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH,
|
2022-03-06 19:30:49 +00:00
|
|
|
};
|
2022-10-27 18:59:47 +00:00
|
|
|
use std::{collections::HashMap, sync::Arc};
|
2023-03-05 18:56:35 +00:00
|
|
|
use vulkano::{
|
2023-10-25 09:01:30 +00:00
|
|
|
command_buffer::allocator::{
|
|
|
|
StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo,
|
|
|
|
},
|
|
|
|
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
|
|
|
device::Queue,
|
2023-03-05 18:56:35 +00:00
|
|
|
};
|
|
|
|
use vulkano_util::{
|
|
|
|
context::{VulkanoConfig, VulkanoContext},
|
2024-02-21 08:08:50 +00:00
|
|
|
renderer::VulkanoWindowRenderer,
|
2023-03-05 18:56:35 +00:00
|
|
|
window::{VulkanoWindows, WindowDescriptor},
|
|
|
|
};
|
2022-06-24 15:27:33 +00:00
|
|
|
use winit::{event_loop::EventLoop, window::WindowId};
|
2022-02-02 16:21:32 +00:00
|
|
|
|
|
|
|
pub struct RenderPipeline {
|
|
|
|
pub compute: GameOfLifeComputePipeline,
|
|
|
|
pub place_over_frame: RenderPassPlaceOverFrame,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenderPipeline {
|
|
|
|
pub fn new(
|
2023-03-24 13:03:49 +00:00
|
|
|
app: &App,
|
2022-02-02 16:21:32 +00:00
|
|
|
compute_queue: Arc<Queue>,
|
|
|
|
gfx_queue: Arc<Queue>,
|
|
|
|
size: [u32; 2],
|
2024-02-21 08:08:50 +00:00
|
|
|
window_renderer: &VulkanoWindowRenderer,
|
2022-02-02 16:21:32 +00:00
|
|
|
) -> RenderPipeline {
|
|
|
|
RenderPipeline {
|
2023-03-24 13:03:49 +00:00
|
|
|
compute: GameOfLifeComputePipeline::new(app, compute_queue, size),
|
2024-02-21 08:08:50 +00:00
|
|
|
place_over_frame: RenderPassPlaceOverFrame::new(app, gfx_queue, window_renderer),
|
2022-02-02 16:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct App {
|
|
|
|
pub context: VulkanoContext,
|
2022-06-24 15:27:33 +00:00
|
|
|
pub windows: VulkanoWindows,
|
2023-03-24 13:03:49 +00:00
|
|
|
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
|
|
|
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
2022-02-02 16:21:32 +00:00
|
|
|
pub pipelines: HashMap<WindowId, RenderPipeline>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
pub fn open(&mut self, event_loop: &EventLoop<()>) {
|
2023-03-05 18:56:35 +00:00
|
|
|
// Create windows & pipelines.
|
2022-06-24 15:27:33 +00:00
|
|
|
let id1 = self.windows.create_window(
|
|
|
|
event_loop,
|
|
|
|
&self.context,
|
|
|
|
&WindowDescriptor {
|
|
|
|
width: WINDOW_WIDTH,
|
|
|
|
height: WINDOW_HEIGHT,
|
|
|
|
title: "Game of Life Primary".to_string(),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
|_| {},
|
|
|
|
);
|
|
|
|
let id2 = self.windows.create_window(
|
|
|
|
event_loop,
|
|
|
|
&self.context,
|
|
|
|
&WindowDescriptor {
|
|
|
|
width: WINDOW2_WIDTH,
|
|
|
|
height: WINDOW2_HEIGHT,
|
|
|
|
title: "Game of Life Secondary".to_string(),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
|_| {},
|
|
|
|
);
|
2022-02-02 16:21:32 +00:00
|
|
|
self.pipelines.insert(
|
2022-06-24 15:27:33 +00:00
|
|
|
id1,
|
2022-02-02 16:21:32 +00:00
|
|
|
RenderPipeline::new(
|
2023-03-24 13:03:49 +00:00
|
|
|
self,
|
2023-03-05 18:56:35 +00:00
|
|
|
// Use same queue.. for synchronization.
|
2022-07-30 06:53:52 +00:00
|
|
|
self.context.graphics_queue().clone(),
|
|
|
|
self.context.graphics_queue().clone(),
|
2022-06-24 15:27:33 +00:00
|
|
|
[
|
|
|
|
(WINDOW_WIDTH / SCALING) as u32,
|
|
|
|
(WINDOW_HEIGHT / SCALING) as u32,
|
|
|
|
],
|
2024-02-21 08:08:50 +00:00
|
|
|
self.windows.get_primary_renderer().unwrap(),
|
2022-02-02 16:21:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
self.pipelines.insert(
|
2022-06-24 15:27:33 +00:00
|
|
|
id2,
|
2022-02-02 16:21:32 +00:00
|
|
|
RenderPipeline::new(
|
2023-03-24 13:03:49 +00:00
|
|
|
self,
|
2022-07-30 06:53:52 +00:00
|
|
|
self.context.graphics_queue().clone(),
|
|
|
|
self.context.graphics_queue().clone(),
|
2022-06-24 15:27:33 +00:00
|
|
|
[
|
|
|
|
(WINDOW2_WIDTH / SCALING) as u32,
|
|
|
|
(WINDOW2_HEIGHT / SCALING) as u32,
|
|
|
|
],
|
2024-02-21 08:08:50 +00:00
|
|
|
self.windows.get_renderer(id2).unwrap(),
|
2022-02-02 16:21:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for App {
|
|
|
|
fn default() -> Self {
|
2023-03-24 13:03:49 +00:00
|
|
|
let context = VulkanoContext::new(VulkanoConfig::default());
|
|
|
|
let command_buffer_allocator = Arc::new(StandardCommandBufferAllocator::new(
|
|
|
|
context.device().clone(),
|
2023-10-25 09:01:30 +00:00
|
|
|
StandardCommandBufferAllocatorCreateInfo {
|
|
|
|
secondary_buffer_count: 32,
|
|
|
|
..Default::default()
|
|
|
|
},
|
2023-03-24 13:03:49 +00:00
|
|
|
));
|
|
|
|
let descriptor_set_allocator = Arc::new(StandardDescriptorSetAllocator::new(
|
|
|
|
context.device().clone(),
|
2023-10-24 14:23:17 +00:00
|
|
|
Default::default(),
|
2023-03-24 13:03:49 +00:00
|
|
|
));
|
|
|
|
|
2022-02-02 16:21:32 +00:00
|
|
|
App {
|
2023-03-24 13:03:49 +00:00
|
|
|
context,
|
2022-06-24 15:27:33 +00:00
|
|
|
windows: VulkanoWindows::default(),
|
2023-03-24 13:03:49 +00:00
|
|
|
command_buffer_allocator,
|
|
|
|
descriptor_set_allocator,
|
2022-02-02 16:21:32 +00:00
|
|
|
pipelines: HashMap::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|