mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 21:08:12 +08:00
Configure gpu surface on non wasm32 targets
This commit is contained in:
committed by
Keavon Chambers
parent
989c8ad5f8
commit
8cd161f087
Generated
+3
@@ -1749,8 +1749,10 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bezier-rs",
|
"bezier-rs",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
|
"chrono",
|
||||||
"dyn-any",
|
"dyn-any",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"fern",
|
||||||
"future-executor",
|
"future-executor",
|
||||||
"futures",
|
"futures",
|
||||||
"glam",
|
"glam",
|
||||||
@@ -1829,6 +1831,7 @@ dependencies = [
|
|||||||
"wgpu",
|
"wgpu",
|
||||||
"wgpu-executor",
|
"wgpu-executor",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
|
"winit",
|
||||||
"xxhash-rust",
|
"xxhash-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,13 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[features]
|
||||||
|
gpu = ["interpreted-executor/gpu", "graphene-std/gpu", "graphene-core/gpu", "wgpu-executor", "gpu-executor"]
|
||||||
|
default = ["wgpu"]
|
||||||
|
wgpu = ["wgpu-executor", "gpu"]
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
@@ -30,6 +35,8 @@ future-executor = { path = "../future-executor", optional = true }
|
|||||||
|
|
||||||
wasm-bindgen = { version = "0.2.86", optional = true }
|
wasm-bindgen = { version = "0.2.86", optional = true }
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
|
fern = { version = "0.6.2", features = ["colored"] }
|
||||||
|
chrono = "0.4.26"
|
||||||
|
|
||||||
[dependencies.document-legacy]
|
[dependencies.document-legacy]
|
||||||
path = "../../document-legacy"
|
path = "../../document-legacy"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
use std::{collections::HashMap, error::Error};
|
use std::{collections::HashMap, error::Error};
|
||||||
|
|
||||||
use document_legacy::{
|
use document_legacy::{
|
||||||
@@ -25,6 +26,28 @@ impl NodeGraphUpdateSender for UpdateLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let colors = ColoredLevelConfig::new()
|
||||||
|
.debug(Color::Magenta)
|
||||||
|
.info(Color::Green)
|
||||||
|
.error(Color::Red);
|
||||||
|
fern::Dispatch::new()
|
||||||
|
.chain(std::io::stdout())
|
||||||
|
.level_for("foodcalc", log::LevelFilter::Trace)
|
||||||
|
.level_for("sqlx", log::LevelFilter::Trace)
|
||||||
|
.level_for("iced", log::LevelFilter::Trace)
|
||||||
|
.level(log::LevelFilter::Trace)
|
||||||
|
.format(move |out, message, record| {
|
||||||
|
out.finish(format_args!(
|
||||||
|
"[{}]{} {}",
|
||||||
|
// This will color the log level only, not the whole line. Just a touch.
|
||||||
|
colors.color(record.level()),
|
||||||
|
chrono::Utc::now().format("[%Y-%m-%d %H:%M:%S]"),
|
||||||
|
message
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.apply()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let document_path = std::env::args().nth(1).expect("No document path provided");
|
let document_path = std::env::args().nth(1).expect("No document path provided");
|
||||||
|
|
||||||
let document_string = std::fs::read_to_string(&document_path).expect("Failed to read document");
|
let document_string = std::fs::read_to_string(&document_path).expect("Failed to read document");
|
||||||
@@ -45,7 +68,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let editor_api = WasmEditorApi {
|
let editor_api = WasmEditorApi {
|
||||||
image_frame: None,
|
image_frame: None,
|
||||||
font_cache: &FontCache::default(),
|
font_cache: &FontCache::default(),
|
||||||
application_io: &WasmApplicationIo::default(),
|
application_io: &block_on(WasmApplicationIo::new()),
|
||||||
node_graph_message_sender: &UpdateLogger {},
|
node_graph_message_sender: &UpdateLogger {},
|
||||||
imaginate_preferences: &ImaginatePreferences::default(),
|
imaginate_preferences: &ImaginatePreferences::default(),
|
||||||
};
|
};
|
||||||
@@ -92,7 +115,16 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork) -> NodeNetwork {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// wrap the inner network in a scope
|
// wrap the inner network in a scope
|
||||||
let nodes = vec![begin_scope(), inner_network, end_scope()];
|
let nodes = vec![
|
||||||
|
begin_scope(),
|
||||||
|
inner_network,
|
||||||
|
DocumentNode {
|
||||||
|
name: "End Scope".to_string(),
|
||||||
|
implementation: DocumentNodeImplementation::proto("graphene_core::memo::EndLetNode<_>"),
|
||||||
|
inputs: vec![NodeInput::node(0, 0), NodeInput::node(1, 0)],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
];
|
||||||
NodeNetwork {
|
NodeNetwork {
|
||||||
inputs: vec![0],
|
inputs: vec![0],
|
||||||
outputs: vec![NodeOutput::new(2, 0)],
|
outputs: vec![NodeOutput::new(2, 0)],
|
||||||
@@ -138,11 +170,3 @@ fn begin_scope() -> DocumentNode {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn end_scope() -> DocumentNode {
|
|
||||||
DocumentNode {
|
|
||||||
name: "End Scope".to_string(),
|
|
||||||
implementation: DocumentNodeImplementation::proto("graphene_core::memo::EndLetNode<_>"),
|
|
||||||
inputs: vec![NodeInput::value(TaggedValue::None, true), NodeInput::value(TaggedValue::ImageFrame(ImageFrame::empty()), true)],
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -10,12 +10,7 @@ license = "MIT OR Apache-2.0"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wasm", "imaginate"]
|
default = ["wasm", "imaginate"]
|
||||||
gpu = [
|
gpu = ["graphene-core/gpu", "gpu-compiler-bin-wrapper", "compilation-client", "gpu-executor"]
|
||||||
"graphene-core/gpu",
|
|
||||||
"gpu-compiler-bin-wrapper",
|
|
||||||
"compilation-client",
|
|
||||||
"gpu-executor",
|
|
||||||
]
|
|
||||||
vulkan = ["gpu", "vulkan-executor"]
|
vulkan = ["gpu", "vulkan-executor"]
|
||||||
wgpu = ["gpu", "wgpu-executor"]
|
wgpu = ["gpu", "wgpu-executor"]
|
||||||
quantization = ["autoquant"]
|
quantization = ["autoquant"]
|
||||||
@@ -62,6 +57,7 @@ js-sys = { version = "0.3.63", optional = true }
|
|||||||
wgpu-types = "0.16.0"
|
wgpu-types = "0.16.0"
|
||||||
wgpu = "0.16.1"
|
wgpu = "0.16.1"
|
||||||
wasm-bindgen-futures = { version = "0.4.36", optional = true }
|
wasm-bindgen-futures = { version = "0.4.36", optional = true }
|
||||||
|
winit = "0.28.6"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|||||||
@@ -51,12 +51,16 @@ impl<'a> From<&'a WasmApplicationIo> for &'a WgpuExecutor {
|
|||||||
pub type WasmEditorApi<'a> = graphene_core::application_io::EditorApi<'a, WasmApplicationIo>;
|
pub type WasmEditorApi<'a> = graphene_core::application_io::EditorApi<'a, WasmApplicationIo>;
|
||||||
|
|
||||||
impl ApplicationIo for WasmApplicationIo {
|
impl ApplicationIo for WasmApplicationIo {
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
type Surface = HtmlCanvasElement;
|
type Surface = HtmlCanvasElement;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
type Surface = winit::window::Window;
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
type Executor = WgpuExecutor;
|
type Executor = WgpuExecutor;
|
||||||
#[cfg(not(feature = "wgpu"))]
|
#[cfg(not(feature = "wgpu"))]
|
||||||
type Executor = ();
|
type Executor = ();
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
fn create_surface(&self) -> SurfaceHandle<Self::Surface> {
|
fn create_surface(&self) -> SurfaceHandle<Self::Surface> {
|
||||||
let wrapper = || {
|
let wrapper = || {
|
||||||
let document = window().expect("should have a window in this context").document().expect("window should have a document");
|
let document = window().expect("should have a window in this context").document().expect("window should have a document");
|
||||||
@@ -90,7 +94,17 @@ impl ApplicationIo for WasmApplicationIo {
|
|||||||
|
|
||||||
wrapper().expect("should be able to set canvas in global scope")
|
wrapper().expect("should be able to set canvas in global scope")
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn create_surface(&self) -> SurfaceHandle<Self::Surface> {
|
||||||
|
let event_loop = winit::event_loop::EventLoop::new();
|
||||||
|
let window = winit::window::WindowBuilder::new().with_title("Graphite").build(&event_loop).unwrap();
|
||||||
|
SurfaceHandle {
|
||||||
|
surface_id: SurfaceId(window.id().into()),
|
||||||
|
surface: window,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
fn destroy_surface(&self, surface_id: SurfaceId) {
|
fn destroy_surface(&self, surface_id: SurfaceId) {
|
||||||
let window = window().expect("should have a window in this context");
|
let window = window().expect("should have a window in this context");
|
||||||
let window = Object::from(window);
|
let window = Object::from(window);
|
||||||
@@ -111,6 +125,9 @@ impl ApplicationIo for WasmApplicationIo {
|
|||||||
wrapper().expect("should be able to set canvas in global scope")
|
wrapper().expect("should be able to set canvas in global scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn destroy_surface(&self, surface_id: SurfaceId) {}
|
||||||
|
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
fn gpu_executor(&self) -> Option<&Self::Executor> {
|
fn gpu_executor(&self) -> Option<&Self::Executor> {
|
||||||
self.gpu_executor.as_ref()
|
self.gpu_executor.as_ref()
|
||||||
@@ -123,7 +140,7 @@ pub type WasmSurfaceHandleFrame = SurfaceHandleFrame<HtmlCanvasElement>;
|
|||||||
pub struct CreateSurfaceNode {}
|
pub struct CreateSurfaceNode {}
|
||||||
|
|
||||||
#[node_macro::node_fn(CreateSurfaceNode)]
|
#[node_macro::node_fn(CreateSurfaceNode)]
|
||||||
async fn create_surface_node<'a: 'input>(editor: WasmEditorApi<'a>) -> Arc<SurfaceHandle<HtmlCanvasElement>> {
|
async fn create_surface_node<'a: 'input>(editor: WasmEditorApi<'a>) -> Arc<SurfaceHandle<<WasmApplicationIo as ApplicationIo>::Surface>> {
|
||||||
editor.application_io.create_surface().into()
|
editor.application_io.create_surface().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
|||||||
),
|
),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(gpu_executor::ReadOutputBufferNode<_, _>, input: Arc<ShaderInput<WgpuExecutor>>, output: Vec<u8>, params: [&WgpuExecutor, ()]),
|
async_node!(gpu_executor::ReadOutputBufferNode<_, _>, input: Arc<ShaderInput<WgpuExecutor>>, output: Vec<u8>, params: [&WgpuExecutor, ()]),
|
||||||
#[cfg(all(feature = "gpu", target_arch = "wasm32"))]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(gpu_executor::CreateGpuSurfaceNode, input: WasmEditorApi, output: Arc<SurfaceHandle<<WgpuExecutor as GpuExecutor>::Surface>>, params: []),
|
async_node!(gpu_executor::CreateGpuSurfaceNode, input: WasmEditorApi, output: Arc<SurfaceHandle<<WgpuExecutor as GpuExecutor>::Surface>>, params: []),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(gpu_executor::RenderTextureNode<_, _>, input: ShaderInputFrame<WgpuExecutor>, output: SurfaceFrame, params: [Arc<SurfaceHandle<<WgpuExecutor as GpuExecutor>::Surface>>, &WgpuExecutor]),
|
async_node!(gpu_executor::RenderTextureNode<_, _>, input: ShaderInputFrame<WgpuExecutor>, output: SurfaceFrame, params: [Arc<SurfaceHandle<<WgpuExecutor as GpuExecutor>::Surface>>, &WgpuExecutor]),
|
||||||
|
|||||||
@@ -396,6 +396,20 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn create_surface(&self, window: SurfaceHandle<winit::window::Window>) -> Result<SurfaceHandle<wgpu::Surface>> {
|
fn create_surface(&self, window: SurfaceHandle<winit::window::Window>) -> Result<SurfaceHandle<wgpu::Surface>> {
|
||||||
let surface = unsafe { self.context.instance.create_surface(&window.surface) }?;
|
let surface = unsafe { self.context.instance.create_surface(&window.surface) }?;
|
||||||
|
|
||||||
|
let surface_caps = surface.get_capabilities(&self.context.adapter);
|
||||||
|
let surface_format = wgpu::TextureFormat::Bgra8Unorm;
|
||||||
|
let config = wgpu::SurfaceConfiguration {
|
||||||
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
|
format: surface_format,
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
present_mode: surface_caps.present_modes[0],
|
||||||
|
alpha_mode: wgpu::CompositeAlphaMode::PreMultiplied,
|
||||||
|
view_formats: vec![wgpu::TextureFormat::Bgra8UnormSrgb],
|
||||||
|
};
|
||||||
|
surface.configure(&self.context.device, &config);
|
||||||
|
|
||||||
let surface_id = window.surface_id;
|
let surface_id = window.surface_id;
|
||||||
Ok(SurfaceHandle { surface_id, surface })
|
Ok(SurfaceHandle { surface_id, surface })
|
||||||
}
|
}
|
||||||
@@ -404,6 +418,7 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
|||||||
impl WgpuExecutor {
|
impl WgpuExecutor {
|
||||||
pub async fn new() -> Option<Self> {
|
pub async fn new() -> Option<Self> {
|
||||||
let context = Context::new().await?;
|
let context = Context::new().await?;
|
||||||
|
println!("wgpu executor created");
|
||||||
|
|
||||||
let texture_bind_group_layout = context.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let texture_bind_group_layout = context.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
entries: &[
|
entries: &[
|
||||||
|
|||||||
Reference in New Issue
Block a user