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:
Amp
2026-07-29 10:03:06 +00:00
co-authored by heaust
parent 0e866596c0
commit 90406ae18f
34 changed files with 1031 additions and 273 deletions
+14 -15
View File
@@ -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" }]);
});