mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 21:48:12 +08:00
Desktop: Add rudimentary support for custom WGPU adapter selection (#3201)
* rudimentary custom wgpu adapter selection * WgpuContextBuilder * wasm fix * fix wasm warnings * Clean up * Review suggestions * fix
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
use graphite_desktop_wrapper::{WgpuContext, WgpuContextBuilder, WgpuFeatures};
|
||||
|
||||
pub(super) async fn create_wgpu_context() -> WgpuContext {
|
||||
let wgpu_context_builder = WgpuContextBuilder::new().with_features(WgpuFeatures::PUSH_CONSTANTS);
|
||||
|
||||
// TODO: add a cli flag to list adapters and exit instead of always printing
|
||||
println!("\nAvailable WGPU adapters:\n{}", wgpu_context_builder.available_adapters_fmt().await);
|
||||
|
||||
// TODO: make this configurable via cli flags instead
|
||||
let wgpu_context = match std::env::var("GRAPHITE_WGPU_ADAPTER").ok().and_then(|s| s.parse().ok()) {
|
||||
None => wgpu_context_builder.build().await,
|
||||
Some(adapter_index) => {
|
||||
tracing::info!("Overriding WGPU adapter selection with adapter index {adapter_index}");
|
||||
wgpu_context_builder.build_with_adapter_selection(|_| Some(adapter_index)).await
|
||||
}
|
||||
}
|
||||
.expect("Failed to create WGPU context");
|
||||
|
||||
// TODO: add a cli flag to list adapters and exit instead of always printing
|
||||
println!("Using WGPU adapter: {:?}", wgpu_context.adapter.get_info());
|
||||
|
||||
wgpu_context
|
||||
}
|
||||
+3
-3
@@ -2,8 +2,6 @@ use std::process::exit;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use winit::event_loop::EventLoop;
|
||||
|
||||
use graphite_desktop_wrapper::WgpuContext;
|
||||
|
||||
pub(crate) mod consts;
|
||||
|
||||
mod app;
|
||||
@@ -14,6 +12,8 @@ mod native_window;
|
||||
mod persist;
|
||||
mod render;
|
||||
|
||||
mod gpu_context;
|
||||
|
||||
use app::App;
|
||||
use cef::CefHandler;
|
||||
use event::CreateAppEventSchedulerEventLoopExt;
|
||||
@@ -31,7 +31,7 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
let wgpu_context = futures::executor::block_on(WgpuContext::new()).unwrap();
|
||||
let wgpu_context = futures::executor::block_on(gpu_context::create_wgpu_context());
|
||||
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let (app_event_sender, app_event_receiver) = std::sync::mpsc::channel();
|
||||
|
||||
@@ -5,8 +5,10 @@ use graphite_editor::messages::prelude::{FrontendMessage, Message};
|
||||
// TODO: Remove usage of this reexport in desktop create and remove this line
|
||||
pub use graphene_std::Color;
|
||||
|
||||
pub use wgpu_executor::Context as WgpuContext;
|
||||
pub use wgpu_executor::WgpuContext;
|
||||
pub use wgpu_executor::WgpuContextBuilder;
|
||||
pub use wgpu_executor::WgpuExecutor;
|
||||
pub use wgpu_executor::WgpuFeatures;
|
||||
|
||||
pub mod messages;
|
||||
use messages::{DesktopFrontendMessage, DesktopWrapperMessage};
|
||||
|
||||
Reference in New Issue
Block a user