render_plugin: Add first SubApp and default schedules
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 7m49s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 7m49s
This commit is contained in:
parent
f585ba78e7
commit
0ee29a3649
7 changed files with 164 additions and 2 deletions
76
crates/engine_vulkan/src/vulkan_context.rs
Normal file
76
crates/engine_vulkan/src/vulkan_context.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use bevy_app::App;
|
||||
use bevy_ecs::resource::Resource;
|
||||
use engine_window::raw_handle::DisplayHandleWrapper;
|
||||
use vulkano::{
|
||||
command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer,
|
||||
allocator::StandardCommandBufferAllocator,
|
||||
},
|
||||
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
||||
device::{Device, Queue},
|
||||
instance::Instance,
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
swapchain::Surface,
|
||||
};
|
||||
use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
||||
|
||||
use super::utils;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanContext {
|
||||
pub instance: Arc<Instance>,
|
||||
pub device: Arc<Device>,
|
||||
pub graphics_queue: Arc<Queue>,
|
||||
|
||||
pub memory_allocator: Arc<StandardMemoryAllocator>,
|
||||
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
}
|
||||
|
||||
impl VulkanContext {
|
||||
pub fn create_surface(
|
||||
&self,
|
||||
window: Arc<impl HasWindowHandle + HasDisplayHandle + Any + Send + Sync>,
|
||||
) -> Arc<Surface> {
|
||||
Surface::from_window(self.instance.clone(), window).unwrap()
|
||||
}
|
||||
|
||||
pub fn create_render_builder(&self) -> AutoCommandBufferBuilder<PrimaryAutoCommandBuffer> {
|
||||
AutoCommandBufferBuilder::primary(
|
||||
self.command_buffer_allocator.clone(),
|
||||
self.graphics_queue.queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&App> for VulkanContext {
|
||||
fn from(app: &App) -> Self {
|
||||
let (device, mut queues) = utils::pick_graphics_device(&instance, &display_handle.0);
|
||||
let graphics_queue = queues.next().unwrap();
|
||||
|
||||
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
|
||||
|
||||
let command_buffer_allocator = Arc::new(StandardCommandBufferAllocator::new(
|
||||
device.clone(),
|
||||
Default::default(),
|
||||
));
|
||||
|
||||
let descriptor_set_allocator = Arc::new(StandardDescriptorSetAllocator::new(
|
||||
device.clone(),
|
||||
Default::default(),
|
||||
));
|
||||
|
||||
Self {
|
||||
instance: instance.clone(),
|
||||
device,
|
||||
graphics_queue,
|
||||
memory_allocator,
|
||||
command_buffer_allocator,
|
||||
descriptor_set_allocator,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue