Graphene Node Runtime
Relevant source files
The following files were used as context for generating this wiki page:
- website/content/volunteer/guide/graphene/_index.md
- website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
- tools/node-docs/src/page_node.rs
- website/content/volunteer/guide/codebase-overview/_index.md
- website/content/volunteer/guide/student-projects/_index.md
- website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Graphene is the node graph engine that powers the Graphite editor, serving as a render engine, runtime environment, and procedural data processor. It is architected as a functional programming language where documents are essentially source code for Graphene programs. These programs represent artwork as a directed acyclic graph (DAG) of interconnected operations, which are recompiled and executed to generate graphical content.
Sources: website/content/volunteer/guide/graphene/_index.md, website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
The runtime is designed to bridge the gap between interpreted flexibility and compiled performance. It manages the execution flow of nodes, which are individual functions running algorithms for graphical operations such as bitmap reading, procedural pattern generation, and vector geometry modification. Graphene integrates deeply with the Rust ecosystem, utilizing its type system, traits, and compiler toolchain (rustc) to ensure high-performance execution on both CPU and GPU.
Sources: website/content/volunteer/guide/graphene/_index.md, website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
Execution Regimes
Graphene operates across three distinct execution regimes to balance the trade-off between latency and performance. This allows for immediate feedback during interactive editing while providing optimized execution for final rendering or exported programs.
| Regime | Description | Usage Context |
|---|---|---|
| Interpreted | Simple execution mode where nodes are run sequentially. This is the primary mode currently implemented. | Real-time interactive editing and previewing. |
| JIT (Just-In-Time) | Dynamically substitutes branches of the graph with compiled nodes to keep latency low while increasing performance. | Transitioning from editing to high-performance playback/rendering. |
| Compiled | The entire graph is compiled into a standalone program using rustc. | Exporting artwork as a standalone executable or asset pipeline. |
Sources: website/content/volunteer/guide/graphene/_index.md
Execution Flow and Optimization
The runtime optimizes execution paths through several strategies:
- Caching and Memoization: The Cache Manager stores intermediate results to avoid recomputing unchanged branches of the graph.
- Batched Execution: Graphene can inline multiple sequentially-run nodes into a single execution unit to reduce overhead.
- Progressive Enhancement: Some nodes support quality flags, allowing them to render a quick, lower-quality result first, followed by higher-quality passes when compute resources are available.
Sources: website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
Node Architecture and Registry
Nodes are the foundational units of computation in Graphene. Each node corresponds to a Rust function and is defined by its metadata and type signatures.
Node Interface and Metadata
A node's interface is defined by its inputs (parameters) and outputs (products). The registry tracks valid input/output type combinations, allowing the runtime to enforce type safety during graph construction.
| Component | Description |
|---|---|
| Primary Input | The first field of a node, often representing the main data stream. |
| Exposed Fields | Parameters visible and adjustable within the graph by default. |
| Context Dependencies | Features the node reads from or sets within the global/local scope. |
| Type Signature | The mapping of input types to output types (e.g., Input -> Output). |
Sources: tools/node-docs/src/page_node.rs:10-40, website/content/volunteer/guide/graphene/_index.md
The Node Registry
The NODE_REGISTRY is a central structure (typically found in node_registry.rs) that allows the interpreted executor to locate Rust functions matching specific node identifiers and type signatures. It supports generic types, though concrete type signatures must currently be listed until the compile server is fully implemented.
Sources: tools/node-docs/src/page_node.rs:9, website/content/volunteer/guide/graphene/_index.md
This diagram shows the relationship between the Node Registry and the metadata used to define node interfaces.
Sources: tools/node-docs/src/page_node.rs:9-50
Distributed Runtime and Scheduling
Graphene is designed as a distributed environment capable of utilizing CPU and GPU resources across local and networked machines.
Distributed Components
- Scheduler: Assigns jobs based on latency, speed, and bandwidth. It prioritizes keeping latency-sensitive jobs (like brush strokes) on the local machine while offloading compute-intensive tasks to the cloud or a local cluster.
- Cache Manager: Works with the scheduler to store results and manage memory/VRAM locality. It prioritizes hardware that already contains the required intermediate data in its local RAM/VRAM.
Sources: website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
GPU Integration
Graphene utilizes the rust-gpu compiler backend to generate compute shaders from the same Rust code used for CPU nodes. This allows for a unified codebase across hardware targets. GPU acceleration is a core focus for the runtime's evolution, particularly for rasterization and complex image processing.
Sources: website/content/volunteer/guide/graphene/_index.md, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
The sequence diagram illustrates how the Runtime Scheduler distributes tasks across various compute resources.
Sources: website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md
Language Concepts and Type System
Graphene treats artwork as a program, where document modification triggers recompilation of an Abstract Syntax Tree (AST).
Concept Mapping
| Graphene Concept | PL Theory Equivalent |
|---|---|
| Node | Function |
| Document | Source Code |
| Graph/Network | Abstract Syntax Tree (AST) |
| Graph Compilation | Linking / JIT / Compilation |
| Graph Execution | Program Execution |
Sources: website/content/volunteer/guide/graphene/_index.md
Type Inference and Rewriting
Graphene implements a type system to enforce safety between node connections. Current research and development focus on:
- Bidirectional Type Inference: Allowing generic types to be inferred based on surrounding context and usage constraints (similar to Hindley-Milner type systems).
- Node Equivalence Rewriting: Using graph theory (such as E-graphs) to simplify sequences of nodes into fewer, equivalent operations (e.g., combining two Transform nodes into one).
Sources: website/content/volunteer/guide/student-projects/_index.md
Summary
The Graphene Node Runtime is the engine responsible for the non-destructive, procedural capabilities of Graphite. By abstracting graphical operations into a functional node-based language and providing a distributed, multi-regime execution environment, Graphene enables a high-performance workflow that scales from local interactive editing to cloud-based batch processing.
Sources: website/content/blog/2022-05-12-distributed-computing-in-the-graphene-runtime.md, website/content/volunteer/guide/graphene/_index.md