Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 7m49s
94 lines
2.6 KiB
Rust
94 lines
2.6 KiB
Rust
use std::sync::Arc;
|
|
|
|
use bevy_ecs::resource::Resource;
|
|
use engine_window::raw_handle::WindowWrapper;
|
|
use utils::{device::create_and_insert_device, instance::create_and_insert_instance};
|
|
use vulkano::{
|
|
command_buffer::allocator::StandardCommandBufferAllocator,
|
|
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
|
device::{Device, DeviceExtensions, DeviceFeatures, Queue},
|
|
instance::Instance,
|
|
memory::allocator::StandardMemoryAllocator,
|
|
};
|
|
use window_render_context::WindowRenderContext;
|
|
|
|
use bevy_app::{App, Plugin};
|
|
|
|
mod utils;
|
|
mod window_render_context;
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanInstance(Arc<Instance>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanDevice(Arc<Device>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanGraphicsQueue(Arc<Queue>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanComputeQueue(Arc<Queue>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanTransferQueue(Arc<Queue>);
|
|
#[derive(Resource)]
|
|
pub struct VulkanMemoryAllocator(Arc<StandardMemoryAllocator>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanCommandBufferAllocator(Arc<StandardCommandBufferAllocator>);
|
|
|
|
#[derive(Resource)]
|
|
pub struct VulkanDescriptorSetAllocator(Arc<StandardDescriptorSetAllocator>);
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum VulkanError {
|
|
#[error("Failed to create vulkan context")]
|
|
FailedToCreateVulkanContext,
|
|
}
|
|
|
|
pub struct VulkanConfig {
|
|
pub instance_layers: Vec<String>,
|
|
pub device_extensions: DeviceExtensions,
|
|
pub device_features: DeviceFeatures,
|
|
pub with_window_surface: bool,
|
|
pub with_graphics_queue: bool,
|
|
pub with_compute_queue: bool,
|
|
pub with_transfer_queue: bool,
|
|
}
|
|
|
|
impl Default for VulkanConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
instance_layers: Vec::default(),
|
|
device_extensions: DeviceExtensions::default(),
|
|
device_features: DeviceFeatures::default(),
|
|
with_window_surface: true,
|
|
with_graphics_queue: true,
|
|
with_compute_queue: true,
|
|
with_transfer_queue: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub struct VulkanPlugin {
|
|
pub vulkan_config: VulkanConfig,
|
|
}
|
|
|
|
impl Plugin for VulkanPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
let world = app.world_mut();
|
|
|
|
create_and_insert_instance(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);
|
|
}
|
|
}
|