Split vulkan resources
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
b977f446d3
commit
f585ba78e7
9 changed files with 483 additions and 244 deletions
|
@ -1,25 +1,86 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use bevy_ecs::resource::Resource;
|
||||
use engine_window::raw_handle::WindowWrapper;
|
||||
use vulkan_context::VulkanContext;
|
||||
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 vulkan_context;
|
||||
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 VulkanPlugin;
|
||||
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 vulkan_context = VulkanContext::from(app as &App);
|
||||
app.world_mut().insert_resource(vulkan_context);
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue