Rebuild core around render graph AST and shared memory

Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae
Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
Amp
2026-08-18 11:58:31 +00:00
co-authored by heaust
parent a23ef37b4d
commit 0e44917f9e
101 changed files with 4409 additions and 2610 deletions
+67
View File
@@ -0,0 +1,67 @@
import {
createGraphAst,
reference,
serializeGraphAst,
} from "@yawn/render-graph-ast";
/** Compiles a plain JavaScript object description into the canonical graph AST. */
export const graphFromObject = (description) => createGraphAst(description);
/** Small mutable authoring facade; `ast()` returns an immutable canonical AST. */
export class RenderGraph {
#id;
#revision;
#nodes = [];
#render = [];
#compute = [];
constructor(id, revision = 1) {
this.#id = id;
this.#revision = revision;
}
renderPipeline(declaration) {
this.#render.push(structuredClone(declaration));
return this;
}
computePipeline(declaration) {
this.#compute.push(structuredClone(declaration));
return this;
}
node(id, executor, { version = 1, parameters = {}, inputs = {}, state = "enabled" } = {}) {
this.#nodes.push({
id,
state,
executor: { key: executor, version },
parameters: structuredClone(parameters),
inputs: structuredClone(inputs),
});
return this;
}
ast() {
return createGraphAst({
id: this.#id,
revision: this.#revision,
pipelines: { render: this.#render, compute: this.#compute },
nodes: this.#nodes,
});
}
serialize() {
return serializeGraphAst(this.ast());
}
load(core) {
return core.compileGraph(this.serialize());
}
}
/** Canonicalizes a JSO/AST and sends its S-expression wire form to Yawn core. */
export function loadGraph(core, description) {
return core.compileGraph(serializeGraphAst(graphFromObject(description)));
}
export { reference as ref, serializeGraphAst };