Skip to content

Commit

Permalink
wip wayland backend
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreEVEN committed May 20, 2024
1 parent d7bcd9d commit e8847c5
Show file tree
Hide file tree
Showing 21 changed files with 2,744 additions and 820 deletions.
490 changes: 476 additions & 14 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion crates/engine/backends/backend_launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ gfx = { path = "../../common/gfx" }
core = { path = "../../core" }
backend_vulkan = { path = "../backend_vulkan" }
backend_vulkan_win32 = { path = "../backend_vulkan_win32" }
plateform_win32 = { path = "../plateform_win32" }
plateform_win32 = { path = "../plateform_win32" }

backend_vulkan_wayland = { path = "../backend_vulkan_wayland" }
plateform_wayland = { path = "../plateform_wayland" }
25 changes: 22 additions & 3 deletions crates/engine/backends/backend_launcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod backend {
use std::sync::Arc;
use backend_vulkan::GfxVulkan;
use backend_vulkan::{GfxVulkan, InstanceCreateInfos};
use gfx::{GfxRef};
use gfx::surface::GfxSurface;
use plateform::window::Window;
Expand All @@ -13,13 +13,32 @@ pub mod backend {
#[cfg(windows)]
use plateform_win32::PlatformWin32;

#[cfg(unix)]
use backend_vulkan_wayland::vk_surface_wayland::VkSurfaceWayland;
#[cfg(unix)]
use plateform_wayland::PlatformWayland;

pub fn create_engine_vulkan() -> Arc<Engine> {
#[cfg(windows)]
Engine::new(PlatformWin32::new(), GfxVulkan::new())
return Engine::new(PlatformWin32::new(), GfxVulkan::new(InstanceCreateInfos {
enable_validation_layers: true,
required_extensions: vec![("VK_KHR_win32_surface".to_string(), true)],
..InstanceCreateInfos::default()
}));
#[cfg(unix)]
return Engine::new(PlatformWayland::new(), GfxVulkan::new(
InstanceCreateInfos {
enable_validation_layers: true,
required_extensions: vec![("VK_KHR_wayland_surface".to_string(), true)],
..InstanceCreateInfos::default()
}
));
}

pub fn create_surface_vulkan(gfx: &GfxRef, window: &Arc<dyn Window>) -> Arc<dyn GfxSurface> {
#[cfg(windows)]
VkSurfaceWin32::new(gfx, format!("{}_surface", window.get_title()), window, 3)
return VkSurfaceWin32::new(gfx, format!("{}_surface", window.get_title()), window, 3);
#[cfg(unix)]
return VkSurfaceWayland::new(gfx, format!("{}_surface", window.get_title()), window, 3);
}
}
17 changes: 10 additions & 7 deletions crates/engine/backends/backend_vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::vk_descriptor_pool::VkDescriptorPool;
use crate::vk_device::VkDevice;
use crate::vk_image::VkImage;
use crate::vk_image_sampler::VkImageSampler;
use crate::vk_instance::{InstanceCreateInfos, VkInstance};
use crate::vk_instance::{VkInstance};
use crate::vk_physical_device::VkPhysicalDevice;
use crate::vk_render_pass::VkRenderPass;
use crate::vk_shader::VkShaderProgram;
Expand Down Expand Up @@ -76,6 +76,13 @@ macro_rules! vk_check {
}
}

#[derive(Default, Clone)]
pub struct InstanceCreateInfos {
pub required_layers: Vec<(String, bool)>,
pub required_extensions: Vec<(String, bool)>,
pub enable_validation_layers: bool,
}

pub struct GfxVulkan {
pub instance: VkInstance,
pub physical_device: PhysicalDevice,
Expand Down Expand Up @@ -145,14 +152,10 @@ impl GfxInterface for GfxVulkan {
}

impl GfxVulkan {
pub fn new() -> GfxRef {
pub fn new(instance_create_infos: InstanceCreateInfos) -> GfxRef {
unsafe { G_VULKAN = Some(ash::Entry::load().expect("failed to load vulkan library")); }

let instance = VkInstance::new(InstanceCreateInfos {
enable_validation_layers: true,
required_extensions: vec![],
..InstanceCreateInfos::default()
}).expect("failed to create instance");
let instance = VkInstance::new(instance_create_infos).expect("failed to create instance");

let physical_device = MaybeUninit::zeroed();
let physical_device_vk = MaybeUninit::zeroed();
Expand Down
10 changes: 1 addition & 9 deletions crates/engine/backends/backend_vulkan/src/vk_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ use gfx::PhysicalDevice;
use crate::{G_VULKAN, g_vulkan, to_c_char};
use crate::vk_physical_device::VkPhysicalDevice;

#[derive(Default, Clone)]
pub struct InstanceCreateInfos {
pub required_layers: Vec<(String, bool)>,
pub required_extensions: Vec<(String, bool)>,
pub enable_validation_layers: bool,
}

pub struct VkInstance {
pub handle: ash::Instance,
pub debug_util_loader: ext::DebugUtils,
Expand All @@ -26,7 +19,7 @@ pub struct VkInstance {
}

impl VkInstance {
pub fn new(create_infos: InstanceCreateInfos) -> Result<VkInstance, std::io::Error> {
pub fn new(create_infos: crate::InstanceCreateInfos) -> Result<VkInstance, std::io::Error> {
// Build extensions and layer
let mut required_layers = Vec::new();
let mut required_extensions = Vec::new();
Expand Down Expand Up @@ -60,7 +53,6 @@ impl VkInstance {
required_extensions.push("VK_EXT_debug_report\0".to_string());
}
required_extensions.push("VK_KHR_surface\0".to_string());
required_extensions.push("VK_KHR_win32_surface\0".to_string());

for layer in &required_layers {
layers_names_raw.push(layer.as_str().as_ptr() as *const c_char);
Expand Down
14 changes: 14 additions & 0 deletions crates/engine/backends/backend_vulkan_wayland/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "backend_vulkan_wayland"
version = "0.1.0"
edition = "2021"

[dependencies]
gfx = {path = "../../common/gfx"}
maths = {path = "../../maths"}
macros = { path = "../../macros" }
backend_vulkan = { path = "../backend_vulkan" }
plateform = {path = "../../common/plateform"}
plateform_wayland = {path = "../plateform_wayland"}
ash = "0.37.2"
gpu-allocator = { version= "0.22.0", default-features = false, features=["vulkan"]}
1 change: 1 addition & 0 deletions crates/engine/backends/backend_vulkan_wayland/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod vk_surface_wayland;
Loading

0 comments on commit e8847c5

Please sign in to comment.