Desktop: Fix non-Vello render mode (#3259)

* fix non vello render mode

* move export overide desision from reneder node to node runtime

* fix

* cleanup

* Fix typo and cleanup export logic

---------

Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
Timon 2025-10-09 11:31:35 +02:00 committed by GitHub
parent 5df3196b58
commit e39fbb8903
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 50 deletions

View File

@ -146,7 +146,7 @@ impl NodeGraphExecutor {
}, },
time, time,
#[cfg(any(feature = "resvg", feature = "vello"))] #[cfg(any(feature = "resvg", feature = "vello"))]
export_format: graphene_std::application_io::ExportFormat::Canvas, export_format: graphene_std::application_io::ExportFormat::Raster,
#[cfg(not(any(feature = "resvg", feature = "vello")))] #[cfg(not(any(feature = "resvg", feature = "vello")))]
export_format: graphene_std::application_io::ExportFormat::Svg, export_format: graphene_std::application_io::ExportFormat::Svg,
render_mode: document.render_mode, render_mode: document.render_mode,
@ -190,10 +190,10 @@ impl NodeGraphExecutor {
let size = bounds[1] - bounds[0]; let size = bounds[1] - bounds[0];
let transform = DAffine2::from_translation(bounds[0]).inverse(); let transform = DAffine2::from_translation(bounds[0]).inverse();
let export_format = if export_config.file_type == FileType::Svg || cfg!(not(feature = "gpu")) { let export_format = if export_config.file_type == FileType::Svg {
graphene_std::application_io::ExportFormat::Svg graphene_std::application_io::ExportFormat::Svg
} else { } else {
graphene_std::application_io::ExportFormat::Texture graphene_std::application_io::ExportFormat::Raster
}; };
let render_config = RenderConfig { let render_config = RenderConfig {

View File

@ -7,7 +7,7 @@ use graph_craft::graphene_compiler::Compiler;
use graph_craft::proto::GraphErrors; use graph_craft::proto::GraphErrors;
use graph_craft::wasm_application_io::EditorPreferences; use graph_craft::wasm_application_io::EditorPreferences;
use graph_craft::{ProtoNodeIdentifier, concrete}; use graph_craft::{ProtoNodeIdentifier, concrete};
use graphene_std::application_io::{ApplicationIo, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig}; use graphene_std::application_io::{ApplicationIo, ExportFormat, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
use graphene_std::bounds::RenderBoundingBox; use graphene_std::bounds::RenderBoundingBox;
use graphene_std::memo::IORecord; use graphene_std::memo::IORecord;
use graphene_std::ops::Convert; use graphene_std::ops::Convert;
@ -212,7 +212,19 @@ impl NodeRuntime {
self.sender.send_generation_response(CompilationResponse { result, node_graph_errors }); self.sender.send_generation_response(CompilationResponse { result, node_graph_errors });
} }
GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, render_config, .. }) => { GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, mut render_config, .. }) => {
// There are cases where we want to export via the svg pipeline eventhough raster was requested.
if matches!(render_config.export_format, ExportFormat::Raster) {
let vello_available = self.editor_api.application_io.as_ref().unwrap().gpu_executor().is_some();
let use_vello = vello_available && self.editor_api.editor_preferences.use_vello();
// On web when the user has disabled vello rendering in the preferences or we are exporting.
// And on all platforms when vello is not supposed to be used.
if !use_vello || cfg!(target_family = "wasm") && render_config.for_export {
render_config.export_format = ExportFormat::Svg;
}
}
let result = self.execute_network(render_config).await; let result = self.execute_network(render_config).await;
let mut responses = VecDeque::new(); let mut responses = VecDeque::new();
// TODO: Only process monitor nodes if the graph has changed, not when only the Footprint changes // TODO: Only process monitor nodes if the graph has changed, not when only the Footprint changes

View File

@ -222,8 +222,7 @@ pub trait GetEditorPreferences {
pub enum ExportFormat { pub enum ExportFormat {
#[default] #[default]
Svg, Svg,
Canvas, Raster,
Texture,
} }
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, serde::Serialize, serde::Deserialize)] #[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]

View File

@ -42,7 +42,6 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
Context -> Table<GradientStops>, Context -> Table<GradientStops>,
)] )]
data: impl Node<Context<'static>, Output = T>, data: impl Node<Context<'static>, Output = T>,
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
) -> RenderIntermediate { ) -> RenderIntermediate {
let render_params = ctx let render_params = ctx
.vararg(0) .vararg(0)
@ -58,39 +57,29 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
data.collect_metadata(&mut metadata, footprint, None); data.collect_metadata(&mut metadata, footprint, None);
let contains_artboard = data.contains_artboard(); let contains_artboard = data.contains_artboard();
let use_vello = { match &render_params.render_output_type {
#[cfg(target_family = "wasm")] RenderOutputTypeRequest::Vello => {
{ let mut scene = vello::Scene::new();
let editor_api = editor_api.eval(None).await;
!render_params.for_export && editor_api.editor_preferences.use_vello() && matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello) let mut context = wgpu_executor::RenderContext::default();
data.render_to_vello(&mut scene, Default::default(), &mut context, render_params);
RenderIntermediate {
ty: RenderIntermediateType::Vello(Arc::new((scene, context))),
metadata,
contains_artboard,
}
} }
#[cfg(not(target_family = "wasm"))] RenderOutputTypeRequest::Svg => {
{ let mut render = SvgRender::new();
let _ = editor_api;
matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello)
}
};
if use_vello { data.render_svg(&mut render, render_params);
let mut scene = vello::Scene::new();
let mut context = wgpu_executor::RenderContext::default(); RenderIntermediate {
data.render_to_vello(&mut scene, Default::default(), &mut context, render_params); ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))),
metadata,
RenderIntermediate { contains_artboard,
ty: RenderIntermediateType::Vello(Arc::new((scene, context))), }
metadata,
contains_artboard,
}
} else {
let mut render = SvgRender::new();
data.render_svg(&mut render, render_params);
RenderIntermediate {
ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))),
metadata,
contains_artboard,
} }
} }
} }
@ -105,8 +94,7 @@ async fn create_context<'a: 'n>(
let render_output_type = match render_config.export_format { let render_output_type = match render_config.export_format {
ExportFormat::Svg => RenderOutputTypeRequest::Svg, ExportFormat::Svg => RenderOutputTypeRequest::Svg,
ExportFormat::Texture => RenderOutputTypeRequest::Vello, ExportFormat::Raster => RenderOutputTypeRequest::Vello,
ExportFormat::Canvas => RenderOutputTypeRequest::Vello,
}; };
let render_params = RenderParams { let render_params = RenderParams {
@ -154,12 +142,7 @@ async fn render<'a: 'n>(
None None
}; };
let mut output_format = render_params.render_output_type; let data = match (render_params.render_output_type, &ty) {
// TODO: Actually request the right thing upfront
if let RenderIntermediateType::Svg(_) = ty {
output_format = RenderOutputTypeRequest::Svg;
}
let data = match (output_format, &ty) {
(RenderOutputTypeRequest::Svg, RenderIntermediateType::Svg(svg_data)) => { (RenderOutputTypeRequest::Svg, RenderIntermediateType::Svg(svg_data)) => {
let mut svg_renderer = SvgRender::new(); let mut svg_renderer = SvgRender::new();
if !contains_artboard && !render_params.hide_artboards { if !contains_artboard && !render_params.hide_artboards {

View File

@ -43,10 +43,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
}, },
DocumentNode { DocumentNode {
call_argument: concrete!(Context), call_argument: concrete!(Context),
inputs: vec![ inputs: vec![NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0)],
NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0),
NodeInput::scope("editor-api"),
],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_intermediate::IDENTIFIER), implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_intermediate::IDENTIFIER),
context_features: graphene_std::ContextDependencies { context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::VARARGS, extract: ContextFeatures::VARARGS,