Skip to content

Commit

Permalink
feat: add vulkan driver
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Sep 4, 2024
1 parent ecb2803 commit 4aaec32
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 97 deletions.
60 changes: 50 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ version = "0.0.0"
edition = "2021"

[workspace]
members = ["crates/renderer", "crates/state", "crates/freya", "crates/elements", "crates/components", "crates/hooks", "crates/common", "crates/core", "crates/testing", "crates/devtools", "crates/torin", "crates/engine", "./examples/installer", "crates/native-core", "crates/native-core-macro"]
members = [
"crates/renderer",
"crates/state",
"crates/freya",
"crates/elements",
"crates/components",
"crates/hooks",
"crates/common",
"crates/core",
"crates/testing",
"crates/devtools",
"crates/torin",
"crates/engine",
"./examples/installer",
"crates/native-core",
"crates/native-core-macro",
]

[features]
tracing-subscriber = ["freya/tracing-subscriber"]
Expand Down Expand Up @@ -42,31 +58,55 @@ torin = { path = "crates/torin", version = "0.2" }
freya-native-core-macro = { path = "crates/native-core-macro", version = "0.2" }
freya-native-core = { path = "crates/native-core", version = "0.2" }

dioxus = { version = "0.5", default-features = false, features = ["macro", "signals", "hooks"]}
dioxus = { version = "0.5", default-features = false, features = [
"macro",
"signals",
"hooks",
] }
dioxus-rsx = { version = "0.5", features = ["hot_reload"] }
dioxus-core-macro = { version = "0.5" }
dioxus-hooks = { version = "0.5" }
dioxus-signals = { version = "0.5" }
dioxus-core = { version = "0.5" }
dioxus-hot-reload = { version = "0.5", features = ["file_watcher"], default-features = false }
dioxus-hot-reload = { version = "0.5", features = [
"file_watcher",
], default-features = false }
dioxus-router = { version = "0.5", default-features = false }
dioxus-sdk = { version = "0.5", features = ["clipboard"]}
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",
"egl",
"x11",
"wayland",
"textlayout",
"svg",
"webp",
] }

gl = "0.14.0"
glutin = "0.32.0"
glutin-winit = "0.5.0"
raw-window-handle = "0.6.0"
winit = "0.30.0"
tokio = { version = "1.33.0", features = ["sync", "rt-multi-thread", "time", "macros"] }
accesskit = { version = "0.16.0", features = ["serde"]}
tokio = { version = "1.33.0", features = [
"sync",
"rt-multi-thread",
"time",
"macros",
] }
accesskit = { version = "0.16.0", features = ["serde"] }
accesskit_winit = "0.22.0"
shipyard = { version = "0.6.2", features = ["proc", "std", "parallel"], default-features = false }
shipyard = { version = "0.6.2", features = [
"proc",
"std",
"parallel",
], default-features = false }
smallvec = "1.13.1"

euclid = "0.22.9"
uuid = { version = "1.4.1", features = ["v4"]}
uuid = { version = "1.4.1", features = ["v4"] }
futures-util = "0.3.30"
futures-task = "0.3.30"
tracing = "0.1"
Expand All @@ -75,7 +115,7 @@ rustc-hash = "2.0.0"

[dev-dependencies]
skia-safe = { workspace = true }
tokio = { workspace = true, features = ["fs"]}
tokio = { workspace = true, features = ["fs"] }
dioxus = { workspace = true }
freya = { workspace = true }
freya-core = { workspace = true }
Expand Down
97 changes: 18 additions & 79 deletions crates/engine/src/skia.rs
Original file line number Diff line number Diff line change
@@ -1,94 +1,33 @@
pub use skia_safe::{
font_style::{
Slant,
Weight,
Width,
},
font_style::{Slant, Weight, Width},
gpu::{
backend_render_targets,
direct_contexts,
gl::{
Format,
FramebufferInfo,
Interface,
},
backend_render_targets, direct_contexts,
gl::{Format, FramebufferInfo, Interface},
surfaces::wrap_backend_render_target,
BackendRenderTarget,
DirectContext,
RecordingContext,
SurfaceOrigin,
vk::{
Alloc, BackendContext, Format as VkFormat, GetProcOf, ImageInfo as VkImageInfo,
ImageLayout, ImageTiling,
},
BackendRenderTarget, DirectContext, RecordingContext, SurfaceOrigin,
},
gradient_shader::GradientShaderColors,
graphics::{
set_resource_cache_single_allocation_byte_limit,
set_resource_cache_total_bytes_limit,
set_resource_cache_single_allocation_byte_limit, set_resource_cache_total_bytes_limit,
},
path::ArcSize,
rrect::Corner,
runtime_effect::Uniform,
surfaces::raster_n32_premul,
svg,
textlayout::{
paragraph::GlyphClusterInfo,
Decoration,
FontCollection,
FontFeature,
LineMetrics,
Paragraph,
ParagraphBuilder,
ParagraphStyle,
PlaceholderStyle,
PositionWithAffinity,
RectHeightStyle,
RectWidthStyle,
StrutStyle,
TextAlign,
TextBaseline,
TextBox,
TextDecoration,
TextDecorationStyle,
TextDirection,
TextHeightBehavior,
TextIndex,
TextRange,
TextShadow,
TextStyle,
TypefaceFontProvider,
paragraph::GlyphClusterInfo, Decoration, FontCollection, FontFeature, LineMetrics,
Paragraph, ParagraphBuilder, ParagraphStyle, PlaceholderStyle, PositionWithAffinity,
RectHeightStyle, RectWidthStyle, StrutStyle, TextAlign, TextBaseline, TextBox,
TextDecoration, TextDecorationStyle, TextDirection, TextHeightBehavior, TextIndex,
TextRange, TextShadow, TextStyle, TypefaceFontProvider,
},
Bitmap,
BlurStyle,
Canvas,
ClipOp,
Color,
ColorSpace,
ColorType,
Data,
EncodedImageFormat,
FilterMode,
FontArguments,
FontMgr,
FontStyle,
IPoint,
IRect,
Image,
ImageInfo,
MaskFilter,
Matrix,
Paint,
PaintStyle,
Path,
PathDirection,
Point,
RRect,
Rect,
RuntimeEffect,
SamplingOptions,
Shader,
Surface,
TileMode,
Typeface,
HSV,
M44,
RGB,
V3,
Bitmap, BlurStyle, Canvas, ClipOp, Color, ColorSpace, ColorType, Data, EncodedImageFormat,
FilterMode, FontArguments, FontMgr, FontStyle, IPoint, IRect, Image, ImageInfo, MaskFilter,
Matrix, Paint, PaintStyle, Path, PathDirection, Point, RRect, Rect, RuntimeEffect,
SamplingOptions, Shader, Surface, TileMode, Typeface, HSV, M44, RGB, V3,
};
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" }
21 changes: 14 additions & 7 deletions crates/renderer/src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
mod gl;
mod vulkan;

use freya_engine::prelude::Surface as SkiaSurface;
pub use gl::*;

use freya_engine::prelude::Surface as SkiaSurface;
use glutin::surface::GlSurface;
use vulkan::VulkanDriver;
use winit::{
dpi::PhysicalSize,
event_loop::ActiveEventLoop,
window::{
Window,
WindowAttributes,
},
window::{Window, WindowAttributes},
};

use crate::LaunchConfig;

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

impl GraphicsDriver {
Expand All @@ -24,13 +25,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 +43,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

0 comments on commit 4aaec32

Please sign in to comment.