vulkano_test/crates/engine_vulkan/src/lib.rs
Florian RICHER 4676b1b5b8
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m39s
engine_vulkan: Refactor queue finding
2025-05-23 14:10:51 +02:00

85 lines
2.3 KiB
Rust

use std::sync::Arc;
use bevy_app::{App, Plugin};
use bevy_ecs::resource::Resource;
use vulkano::{
command_buffer::allocator::StandardCommandBufferAllocator,
descriptor_set::allocator::StandardDescriptorSetAllocator,
device::{Device, DeviceExtensions, DeviceFeatures, Queue},
instance::Instance,
memory::allocator::StandardMemoryAllocator,
};
mod device;
mod instance;
mod queues;
use crate::{device::create_and_insert_device, instance::create_and_insert_instance};
#[derive(Resource, Clone)]
pub struct VulkanInstance(pub Arc<Instance>);
#[derive(Resource, Clone)]
pub struct VulkanDevice(pub Arc<Device>);
#[derive(Resource, Clone)]
pub struct VulkanGraphicsQueue(pub Arc<Queue>);
#[derive(Resource, Clone)]
pub struct VulkanComputeQueue(pub Arc<Queue>);
#[derive(Resource, Clone)]
pub struct VulkanTransferQueue(pub Arc<Queue>);
#[derive(Resource, Clone)]
pub struct VulkanMemoryAllocator(pub Arc<StandardMemoryAllocator>);
#[derive(Resource, Clone)]
pub struct VulkanCommandBufferAllocator(pub Arc<StandardCommandBufferAllocator>);
#[derive(Resource, Clone)]
pub struct VulkanDescriptorSetAllocator(pub 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);
}
}