Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Vulkan driver #852

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dioxus-hot-reload = { version = "0.5", features = ["file_watcher"], default-feat
dioxus-router = { version = "0.5", default-features = false }
dioxus-sdk = { version = "0.5", features = ["clipboard"]}

skia-safe = { version = "0.75.0", features = ["gl", "textlayout", "svg"] }
skia-safe = { version = "0.75.0", features = ["gl", "vulkan", "textlayout", "svg"] }

gl = "0.14.0"
glutin = "0.32.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ glutin = { workspace = true }
[target."cfg(target_os = \"linux\")".dependencies.skia-safe]
workspace = true
optional = true
features = ["gl", "textlayout", "svg", "x11", "wayland"]
features = ["gl", "vulkan", "textlayout", "svg", "x11", "wayland"]
9 changes: 9 additions & 0 deletions crates/engine/src/skia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ pub use skia_safe::{
Interface,
},
surfaces::wrap_backend_render_target,
vk::{
Alloc,
BackendContext,
Format as VkFormat,
GetProcOf,
ImageInfo as VkImageInfo,
ImageLayout,
ImageTiling,
},
BackendRenderTarget,
DirectContext,
RecordingContext,
Expand Down
5 changes: 4 additions & 1 deletion crates/renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ winit = { workspace = true }
accesskit = { workspace = true }
accesskit_winit = { workspace = true }
tracing = { workspace = true }
futures-task ={ workspace = true }
futures-task = { workspace = true }
futures-util = { workspace = true }

itertools = "0.13.0"
uuid = { workspace = true }
image = "0.25.0"
pin-utils = "0.1.0"

ash = { version = "^0.37.2" }
vulkano = { version = "^0.34.0" }
13 changes: 11 additions & 2 deletions crates/renderer/src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod gl;
mod vulkan;

use freya_engine::prelude::Surface as SkiaSurface;
pub use gl::*;
use glutin::surface::GlSurface;
use vulkan::VulkanDriver;
use winit::{
dpi::PhysicalSize,
event_loop::ActiveEventLoop,
Expand All @@ -16,6 +18,7 @@ use crate::LaunchConfig;

pub enum GraphicsDriver {
OpenGl(OpenGLDriver),
Vulkan(VulkanDriver),
}

impl GraphicsDriver {
Expand All @@ -24,13 +27,15 @@ impl GraphicsDriver {
window_attributes: WindowAttributes,
config: &LaunchConfig<State>,
) -> (Self, Window, SkiaSurface) {
let (driver, window, surface) = OpenGLDriver::new(event_loop, window_attributes, config);
(Self::OpenGl(driver), window, surface)
let (driver, window, surface) = VulkanDriver::new(event_loop, window_attributes, config);

(Self::Vulkan(driver), window, surface)
}

pub fn make_current(&mut self) {
match self {
Self::OpenGl(gl) => gl.make_current(),
Self::Vulkan(_) => {}
}
}

Expand All @@ -40,12 +45,16 @@ impl GraphicsDriver {
gl.gr_context.flush_and_submit();
gl.gl_surface.swap_buffers(&gl.gl_context).unwrap();
}
Self::Vulkan(vk) => {
vk.gr_context.flush_and_submit();
}
}
}

pub fn resize(&mut self, size: PhysicalSize<u32>) -> (SkiaSurface, SkiaSurface) {
match self {
Self::OpenGl(gl) => gl.resize(size),
Self::Vulkan(vk) => vk.resize(size),
}
}
}
Loading
Loading