render_plugin: Begin add window plugin
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 3m7s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 3m7s
This commit is contained in:
parent
0ee29a3649
commit
ae0a2be097
8 changed files with 134 additions and 48 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -676,7 +676,10 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy_app",
|
"bevy_app",
|
||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
|
"engine_vulkan",
|
||||||
|
"engine_window",
|
||||||
"log",
|
"log",
|
||||||
|
"vulkano",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -7,3 +7,6 @@ edition = "2024"
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
bevy_app = { workspace = true }
|
bevy_app = { workspace = true }
|
||||||
bevy_ecs = { workspace = true }
|
bevy_ecs = { workspace = true }
|
||||||
|
vulkano = { workspace = true }
|
||||||
|
engine_vulkan = { workspace = true }
|
||||||
|
engine_window = { workspace = true }
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
use bevy_app::{App, AppLabel, Last, Plugin, SubApp};
|
use bevy_app::{App, AppLabel, Last, Plugin, SubApp};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
schedule::{IntoScheduleConfigs, Schedule, ScheduleLabel, SystemSet},
|
schedule::{IntoScheduleConfigs, Schedule, ScheduleLabel, SystemSet},
|
||||||
system::Commands,
|
system::{Commands, Res},
|
||||||
|
world::World,
|
||||||
};
|
};
|
||||||
|
use engine_vulkan::{
|
||||||
|
VulkanCommandBufferAllocator, VulkanDescriptorSetAllocator, VulkanDevice, VulkanGraphicsQueue,
|
||||||
|
VulkanMemoryAllocator,
|
||||||
|
};
|
||||||
|
use engine_window::raw_handle::WindowWrapper;
|
||||||
|
use window::WindowRenderPlugin;
|
||||||
|
|
||||||
|
pub mod window;
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
||||||
pub enum RenderSystems {
|
pub enum RenderSystems {
|
||||||
|
ManageViews,
|
||||||
Prepare,
|
Prepare,
|
||||||
Queue,
|
Queue,
|
||||||
Render,
|
Render,
|
||||||
|
@ -33,33 +43,69 @@ pub struct RenderApp;
|
||||||
pub struct RenderPlugin;
|
pub struct RenderPlugin;
|
||||||
|
|
||||||
impl Plugin for RenderPlugin {
|
impl Plugin for RenderPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, _app: &mut App) {}
|
||||||
|
|
||||||
|
fn ready(&self, app: &App) -> bool {
|
||||||
|
let world = app.world();
|
||||||
|
|
||||||
|
world.get_resource::<WindowWrapper>().is_some()
|
||||||
|
&& world.get_resource::<VulkanDevice>().is_some()
|
||||||
|
&& world.get_resource::<VulkanGraphicsQueue>().is_some()
|
||||||
|
&& world.get_resource::<VulkanMemoryAllocator>().is_some()
|
||||||
|
&& world
|
||||||
|
.get_resource::<VulkanCommandBufferAllocator>()
|
||||||
|
.is_some()
|
||||||
|
&& world
|
||||||
|
.get_resource::<VulkanDescriptorSetAllocator>()
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish(&self, app: &mut App) {
|
||||||
let mut render_app = SubApp::new();
|
let mut render_app = SubApp::new();
|
||||||
render_app.update_schedule = Some(Render.intern());
|
render_app.update_schedule = Some(Render.intern());
|
||||||
|
|
||||||
render_app.add_schedule(Render::base_schedule());
|
render_app.add_schedule(Render::base_schedule());
|
||||||
|
|
||||||
render_app.add_systems(Render, test_prepare.in_set(RenderSystems::Prepare));
|
extract_app_resources(app.world_mut(), render_app.world_mut());
|
||||||
render_app.add_systems(Render, test_queue.in_set(RenderSystems::Queue));
|
|
||||||
render_app.add_systems(Render, test_render.in_set(RenderSystems::Render));
|
|
||||||
render_app.add_systems(Render, test_present.in_set(RenderSystems::Present));
|
|
||||||
|
|
||||||
app.insert_sub_app(RenderApp, render_app);
|
app.insert_sub_app(RenderApp, render_app);
|
||||||
|
|
||||||
|
app.add_plugins(WindowRenderPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup(&self, app: &mut App) {
|
||||||
|
app.remove_sub_app(RenderApp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_prepare(mut commands: Commands) {
|
fn extract_app_resources(world: &mut World, render_world: &mut World) {
|
||||||
log::info!("test_prepare");
|
let window_wrapper = world
|
||||||
}
|
.get_resource::<WindowWrapper>()
|
||||||
|
.expect("Failed to get WindowWrapper. Check is WindowPlugin is added before RenderPlugin.");
|
||||||
|
|
||||||
fn test_queue(mut commands: Commands) {
|
let vulkan_device = world
|
||||||
log::info!("test_queue");
|
.get_resource::<VulkanDevice>()
|
||||||
}
|
.expect("Failed to get Vulkan device. Check is VulkanPlugin is added before RenderPlugin.");
|
||||||
|
|
||||||
fn test_render(mut commands: Commands) {
|
let vulkan_graphics_queue = world.get_resource::<VulkanGraphicsQueue>().expect(
|
||||||
log::info!("test_render");
|
"Failed to get Vulkan graphics queue. Check is VulkanPlugin is added before RenderPlugin.",
|
||||||
}
|
);
|
||||||
|
|
||||||
fn test_present(mut commands: Commands) {
|
let vulkan_memory_allocator = world
|
||||||
log::info!("test_present");
|
.get_resource::<VulkanMemoryAllocator>()
|
||||||
|
.expect("Failed to get Vulkan memory allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||||
|
|
||||||
|
let vulkan_command_buffer_allocator = world
|
||||||
|
.get_resource::<VulkanCommandBufferAllocator>()
|
||||||
|
.expect("Failed to get Vulkan command buffer allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||||
|
|
||||||
|
let vulkan_descriptor_set_allocator = world
|
||||||
|
.get_resource::<VulkanDescriptorSetAllocator>()
|
||||||
|
.expect("Failed to get Vulkan descriptor set allocator. Check is VulkanPlugin is added before RenderPlugin.");
|
||||||
|
|
||||||
|
render_world.insert_resource(vulkan_device.clone());
|
||||||
|
render_world.insert_resource(vulkan_graphics_queue.clone());
|
||||||
|
render_world.insert_resource(vulkan_memory_allocator.clone());
|
||||||
|
render_world.insert_resource(vulkan_command_buffer_allocator.clone());
|
||||||
|
render_world.insert_resource(vulkan_descriptor_set_allocator.clone());
|
||||||
|
render_world.insert_resource(window_wrapper.clone());
|
||||||
}
|
}
|
||||||
|
|
35
crates/engine_render/src/window/mod.rs
Normal file
35
crates/engine_render/src/window/mod.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use bevy_app::{App, Plugin};
|
||||||
|
use bevy_ecs::resource::Resource;
|
||||||
|
use vulkano::{
|
||||||
|
image::view::ImageView, pipeline::graphics::viewport::Viewport, swapchain::Swapchain,
|
||||||
|
sync::GpuFuture,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::RenderApp;
|
||||||
|
|
||||||
|
pub struct WindowSurfaceData {
|
||||||
|
pub swapchain: Arc<Swapchain>,
|
||||||
|
pub attachment_image_views: Vec<Arc<ImageView>>,
|
||||||
|
pub viewport: Viewport,
|
||||||
|
pub recreate_swapchain: bool,
|
||||||
|
pub previous_frame_end: Option<Box<dyn GpuFuture + Send + Sync>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Default)]
|
||||||
|
pub struct WindowSurface {
|
||||||
|
pub surface: Option<WindowSurfaceData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WindowRenderPlugin;
|
||||||
|
|
||||||
|
impl Plugin for WindowRenderPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
let render_app = app
|
||||||
|
.get_sub_app_mut(RenderApp)
|
||||||
|
.expect("Failed to get RenderApp. Check is RenderPlugin is added.");
|
||||||
|
|
||||||
|
render_app.init_resource::<WindowSurface>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,28 +17,29 @@ use bevy_app::{App, Plugin};
|
||||||
mod utils;
|
mod utils;
|
||||||
mod window_render_context;
|
mod window_render_context;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanInstance(Arc<Instance>);
|
pub struct VulkanInstance(pub Arc<Instance>);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanDevice(Arc<Device>);
|
pub struct VulkanDevice(pub Arc<Device>);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanGraphicsQueue(Arc<Queue>);
|
pub struct VulkanGraphicsQueue(pub Arc<Queue>);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanComputeQueue(Arc<Queue>);
|
pub struct VulkanComputeQueue(pub Arc<Queue>);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanTransferQueue(Arc<Queue>);
|
pub struct VulkanTransferQueue(pub Arc<Queue>);
|
||||||
#[derive(Resource)]
|
|
||||||
pub struct VulkanMemoryAllocator(Arc<StandardMemoryAllocator>);
|
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanCommandBufferAllocator(Arc<StandardCommandBufferAllocator>);
|
pub struct VulkanMemoryAllocator(pub Arc<StandardMemoryAllocator>);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct VulkanDescriptorSetAllocator(Arc<StandardDescriptorSetAllocator>);
|
pub struct VulkanCommandBufferAllocator(pub Arc<StandardCommandBufferAllocator>);
|
||||||
|
|
||||||
|
#[derive(Resource, Clone)]
|
||||||
|
pub struct VulkanDescriptorSetAllocator(pub Arc<StandardDescriptorSetAllocator>);
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum VulkanError {
|
pub enum VulkanError {
|
||||||
|
@ -82,13 +83,4 @@ impl Plugin for VulkanPlugin {
|
||||||
create_and_insert_instance(world, &self.vulkan_config);
|
create_and_insert_instance(world, &self.vulkan_config);
|
||||||
create_and_insert_device(world, &self.vulkan_config);
|
create_and_insert_device(world, &self.vulkan_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ready(&self, app: &App) -> bool {
|
|
||||||
app.world().get_resource::<WindowWrapper>().is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(&self, app: &mut App) {
|
|
||||||
let window_render_context = WindowRenderContext::from(app as &App);
|
|
||||||
app.world_mut().insert_resource(window_render_context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use bevy_app::{App, AppExit, Plugin, PluginsState};
|
use bevy_app::{App, AppExit, Plugin, PluginsState};
|
||||||
use config::WindowConfig;
|
use config::WindowConfig;
|
||||||
use raw_handle::{DisplayHandleWrapper, EventLoopProxyWrapper};
|
use raw_handle::{DisplayHandleWrapper, EventLoopProxyWrapper, WindowWrapper};
|
||||||
use state::WindowState;
|
use state::WindowState;
|
||||||
use winit::event_loop::EventLoop;
|
use winit::event_loop::EventLoop;
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ impl<T: 'static> EventLoopProxyWrapper<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct DisplayHandleWrapper(pub winit::event_loop::OwnedDisplayHandle);
|
pub struct DisplayHandleWrapper(pub winit::event_loop::OwnedDisplayHandle);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct WindowWrapper(pub Arc<Window>);
|
pub struct WindowWrapper(pub Arc<Window>);
|
||||||
|
|
|
@ -33,6 +33,13 @@ pub fn init(app: &mut App) {
|
||||||
VulkanPlugin { vulkan_config },
|
VulkanPlugin { vulkan_config },
|
||||||
RenderPlugin,
|
RenderPlugin,
|
||||||
));
|
));
|
||||||
// Window::new(app, window_config).unwrap();
|
|
||||||
// Vulkan::new(app).unwrap();
|
// app.get_sub_app_mut(RenderApp)
|
||||||
|
// .expect("Failed to get RenderApp. Check is RenderPlugin is added.")
|
||||||
|
// .add_systems(Render, test_system.in_set(RenderSystems::Prepare));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn test_system(vulkan_device: Res<VulkanDevice>, vulkan_graphics_queue: Res<VulkanGraphicsQueue>) {
|
||||||
|
// log::trace!("vulkan_device: {:?}", vulkan_device.0);
|
||||||
|
// log::trace!("vulkan_graphics_queue: {:?}", vulkan_graphics_queue.0);
|
||||||
|
// }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue