feat: add variadic render graph logic nodes
Amp-Thread-ID: https://ampcode.com/threads/T-019f9d91-77c1-7206-a60f-ed6554ce92ab Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
@@ -36,7 +36,7 @@ test("production render graph composition passes fxnode's public validator", asy
|
||||
result.ok ? undefined : JSON.stringify(result.issues, null, 2),
|
||||
);
|
||||
assert.equal(fxNodeComposition.schemaVersion, 2);
|
||||
assert.equal(fxNodeComposition.version, 10);
|
||||
assert.equal(fxNodeComposition.version, 11);
|
||||
assert.equal(Object.keys(fxNodeComposition.nodes).length, 42);
|
||||
assert.ok(
|
||||
Object.values(fxNodeComposition.nodes).every(
|
||||
|
||||
@@ -2,18 +2,46 @@ import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { culling } from "../static/render-graph/presets.js";
|
||||
import {
|
||||
CATALOG_VERSION, semanticCatalog, nodeDefinitions, descriptors,
|
||||
CATALOG_VERSION, GRAPH_ID, semanticCatalog, nodeDefinitions, descriptors, socketTypes,
|
||||
} from "../static/render-graph/catalog.js";
|
||||
import { adaptFxNodeSnapshot, mapAuthoringDiagnostic } from "../static/render-graph/adapter.js";
|
||||
|
||||
test("catalog v10 exposes the final mesh, pipeline, and typed-expression contracts", () => {
|
||||
assert.equal(CATALOG_VERSION, 10);
|
||||
const authoredNode = (id, typeId) => {
|
||||
const definition = nodeDefinitions[typeId];
|
||||
return {
|
||||
id, typeId, typeVersion: definition.version,
|
||||
position: { x: 0, y: 0 }, size: { x: 200, y: 120 }, label: id,
|
||||
parameters: Object.fromEntries(Object.entries(definition.parameters)
|
||||
.map(([key, schema]) => [key, structuredClone(schema.default)])),
|
||||
sockets: Object.entries(definition.sockets).map(([key, socket]) => ({
|
||||
id: `${id}:${key}`, key, label: socket.title, direction: socket.direction,
|
||||
dataType: socket.type,
|
||||
accepts: socket.direction === "input" ? [...socketTypes[socket.type].acceptsFrom] : [],
|
||||
maxIncomingLinks: socket.maxIncomingLinks,
|
||||
...(socket.value ? { defaultValue: structuredClone(socket.value.default) } : {}),
|
||||
visible: socket.visible,
|
||||
})),
|
||||
muted: false, collapsed: false, extensions: {}, known: true,
|
||||
};
|
||||
};
|
||||
|
||||
const authoredLink = (id, from, to = "target", muted = false) => ({
|
||||
id, fromNodeId: from, fromSocketId: `${from}:value`,
|
||||
toNodeId: to, toSocketId: `${to}:inputs`, muted, extensions: {},
|
||||
});
|
||||
|
||||
test("catalog v11 exposes the final mesh, pipeline, and typed-expression contracts", () => {
|
||||
assert.equal(CATALOG_VERSION, 11);
|
||||
assert.deepEqual(semanticCatalog.mesh.outputs, {
|
||||
mesh: { type: "mesh_data" }, type: { type: "u32x16" }, localAabb: { type: "local_aabb" },
|
||||
});
|
||||
assert.equal(semanticCatalog.mesh.version, 2);
|
||||
assert.equal(nodeDefinitions.mesh.sockets.localAabb.title, "Local AABB");
|
||||
assert.equal(semanticCatalog.pipeline.version, 4);
|
||||
assert.equal(semanticCatalog.pipeline.inputs.predicate.required, false);
|
||||
assert.deepEqual(semanticCatalog.pipeline.inputs.predicate.cardinality, { minimum: 0, maximum: 1 });
|
||||
assert.deepEqual(semanticCatalog.and.inputs.inputs.cardinality, { minimum: 0, maximum: 8 });
|
||||
assert.equal(nodeDefinitions.and.sockets.inputs.maxIncomingLinks, 8);
|
||||
assert.equal(nodeDefinitions.and.sockets.inputs.value, null);
|
||||
assert.deepEqual(nodeDefinitions.texture.parameters.sampleCount.enum, ["1", "4"]);
|
||||
for (const key of ["and", "xnor", "equals_f32", "greater_than_u32", "combine_vec4",
|
||||
"separate_mat4", "combine_u32_bits", "separate_u32x16", "separate_local_aabb"])
|
||||
@@ -26,10 +54,10 @@ test("catalog v10 exposes the final mesh, pipeline, and typed-expression contrac
|
||||
|
||||
test("current culling fixture uses type-bit predicates and final socket versions", () => {
|
||||
const byId = Object.fromEntries(culling.nodes.map((node) => [node.id, node]));
|
||||
assert.deepEqual(byId.cull.inputs.localAabb, { node: "mesh", socket: "localAabb" });
|
||||
assert.deepEqual(byId.type_words.inputs.value, { node: "mesh", socket: "type" });
|
||||
assert.deepEqual(byId.cull.inputs.localAabb, [{ node: "mesh", socket: "localAabb" }]);
|
||||
assert.deepEqual(byId.type_words.inputs.value, [{ node: "mesh", socket: "type" }]);
|
||||
assert.equal(byId.ground.executor.version, 4);
|
||||
assert.equal(byId.ground.inputs.predicate.node, "ground_final");
|
||||
assert.equal(byId.ground.inputs.predicate[0].node, "ground_class");
|
||||
});
|
||||
|
||||
test("compiler texture sockets expose policy metadata without literal widgets", () => {
|
||||
@@ -48,3 +76,29 @@ test("removed architecture is absent from the authoring catalog", () => {
|
||||
for (const removedSocket of ["isVisible", "localAabbs", "activation"])
|
||||
assert.equal(serialized.includes(`\"${removedSocket}\"`), false);
|
||||
});
|
||||
|
||||
test("adapter preserves ordered multisocket links and indexed diagnostics", () => {
|
||||
const raw = {
|
||||
graphId: GRAPH_ID, catalogVersion: CATALOG_VERSION,
|
||||
nodes: ["source_a", "source_b", "source_c"].map((id) => authoredNode(id, "not"))
|
||||
.concat(authoredNode("target", "and")),
|
||||
links: [
|
||||
authoredLink("link_a", "source_a"),
|
||||
authoredLink("link_muted", "source_c", "target", true),
|
||||
authoredLink("link_b", "source_b"),
|
||||
],
|
||||
metadata: {}, version: 1,
|
||||
};
|
||||
const graph = adaptFxNodeSnapshot(raw, 2);
|
||||
const targetIndex = graph.nodes.findIndex((node) => node.id === "target");
|
||||
assert.equal(graph.schemaVersion, 3);
|
||||
assert.deepEqual(graph.nodes[targetIndex].inputs.inputs, [
|
||||
{ node: "source_a", socket: "value" },
|
||||
{ node: "source_b", socket: "value" },
|
||||
]);
|
||||
const diagnostic = mapAuthoringDiagnostic(graph, {
|
||||
code: "GRAPH_SOCKET_TYPE_MISMATCH",
|
||||
details: { path: `nodes[${targetIndex}].inputs.inputs[1].node` },
|
||||
});
|
||||
assert.equal(diagnostic.source.linkId, "link_b");
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { descriptors } from "../static/render-graph/catalog.js";
|
||||
test("all presets use current schemas, versions, and one frame output", () => {
|
||||
assert.equal(Object.keys(presets.renderGraphPresets).length, 13);
|
||||
for (const [name, graph] of Object.entries(presets.renderGraphPresets)) {
|
||||
assert.deepEqual([graph.schemaVersion, graph.revision], [2, 1], name);
|
||||
assert.deepEqual([graph.schemaVersion, graph.revision], [3, 2], name);
|
||||
assert.equal(new Set(graph.nodes.map((node) => node.id)).size, graph.nodes.length, name);
|
||||
assert.equal(graph.nodes.filter((node) => node.executor.key === "frame_out").length, 1, name);
|
||||
for (const node of graph.nodes)
|
||||
@@ -23,14 +23,13 @@ test("all presets use current schemas, versions, and one frame output", () => {
|
||||
test("presets classify demo-owned enable and material bits through type.words[0] predicates", () => {
|
||||
for (const [name, graph] of Object.entries(presets.renderGraphPresets)) {
|
||||
const byId = Object.fromEntries(graph.nodes.map((node) => [node.id, node]));
|
||||
assert.deepEqual(byId.type_words.inputs.value, { node: "mesh", socket: "type" }, name);
|
||||
assert.deepEqual(byId.type_bits.inputs.value, { node: "type_words", socket: "word0" }, name);
|
||||
const suffix = name === "culling" ? "_final" : "_class";
|
||||
assert.deepEqual(byId.ground.inputs.predicate, { node: `ground${suffix}`, socket: "value" }, name);
|
||||
assert.deepEqual(byId.pbr.inputs.predicate, { node: name === "culling" ? "pbr_final" : "standard_class", socket: "value" }, name);
|
||||
assert.deepEqual(byId.pbr_double.inputs.predicate, { node: name === "culling" ? "pbr_double_final" : "double_class", socket: "value" }, name);
|
||||
assert.deepEqual(byId.type_words.inputs.value, [{ node: "mesh", socket: "type" }], name);
|
||||
assert.deepEqual(byId.type_bits.inputs.value, [{ node: "type_words", socket: "word0" }], name);
|
||||
assert.deepEqual(byId.ground.inputs.predicate, [{ node: "ground_class", socket: "value" }], name);
|
||||
assert.deepEqual(byId.pbr.inputs.predicate, [{ node: "standard_class", socket: "value" }], name);
|
||||
assert.deepEqual(byId.pbr_double.inputs.predicate, [{ node: "double_class", socket: "value" }], name);
|
||||
for (const pipeline of [byId.ground, byId.pbr, byId.pbr_double]) {
|
||||
assert.deepEqual(pipeline.inputs.mesh, { node: "mesh", socket: "mesh" });
|
||||
assert.deepEqual(pipeline.inputs.mesh, [{ node: "mesh", socket: "mesh" }]);
|
||||
assert.equal(pipeline.executor.version, 4);
|
||||
}
|
||||
}
|
||||
@@ -39,11 +38,11 @@ test("presets classify demo-owned enable and material bits through type.words[0]
|
||||
test("culling adds a local-AABB expression to each material predicate", () => {
|
||||
const byId = Object.fromEntries(presets.culling.nodes.map((node) => [node.id, node]));
|
||||
assert.deepEqual(byId.cull.inputs, {
|
||||
mesh: { node: "mesh", socket: "mesh" }, localAabb: { node: "mesh", socket: "localAabb" },
|
||||
mesh: [{ node: "mesh", socket: "mesh" }], localAabb: [{ node: "mesh", socket: "localAabb" }],
|
||||
});
|
||||
assert.deepEqual(byId.not_culled.inputs.operand, { node: "cull", socket: "isFrustumCulled" });
|
||||
for (const id of ["ground", "pbr", "pbr_double"])
|
||||
assert.equal(byId[id].inputs.predicate.node.endsWith("_final"), true);
|
||||
assert.deepEqual(byId.not_culled.inputs.operand, [{ node: "cull", socket: "isFrustumCulled" }]);
|
||||
for (const id of ["ground_class", "standard_class", "double_class"])
|
||||
assert.equal(byId[id].inputs.inputs.at(-1).node, "not_culled");
|
||||
});
|
||||
|
||||
test("implicit presets start disconnected and then chain both attachments", () => {
|
||||
@@ -51,9 +50,9 @@ test("implicit presets start disconnected and then chain both attachments", () =
|
||||
const byId = Object.fromEntries(presets[name].nodes.map((node) => [node.id, node]));
|
||||
assert.equal("colorTarget" in byId.ground.inputs, false, name);
|
||||
assert.equal("depthTarget" in byId.ground.inputs, false, name);
|
||||
assert.deepEqual(byId.pbr.inputs.colorTarget, { node: "ground", socket: "color" }, name);
|
||||
assert.deepEqual(byId.pbr.inputs.depthTarget, { node: "ground", socket: "depth" }, name);
|
||||
assert.deepEqual(byId.pbr.inputs.colorTarget, [{ node: "ground", socket: "color" }], name);
|
||||
assert.deepEqual(byId.pbr.inputs.depthTarget, [{ node: "ground", socket: "depth" }], name);
|
||||
}
|
||||
const midnight = Object.fromEntries(presets.midnight.nodes.map((node) => [node.id, node]));
|
||||
assert.deepEqual(midnight.ground.inputs.colorTarget, { node: "ldr", socket: "texture" });
|
||||
assert.deepEqual(midnight.ground.inputs.colorTarget, [{ node: "ldr", socket: "texture" }]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user