Shader library: fingerprint without node positions, a drag no longer recompiles (#65)
game-maker / suite (push) Successful in 9m5s

shaderFingerprint(graph) covers node id/type/params/ports and edge endpoints only;
x/y, collapsed, folded and edge ids stay out. ShaderLibrary keys on it and counts
compiles (__gm.shaderCompiles()). Measured before: one compile per preview step of a
node drag (12 for a harness drag); after: 0, a param change exactly +1.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Fable 5.1 committed 2026-09-13 18:00:48 +02:00
1 parent 016e83c9b5
commit 102a649a35
6 files changed
+82 -6

No files matched your search

+28 -2
View File
@@ -5,7 +5,14 @@
*/
import { describe, expect, it } from 'vitest';
import { CreateAssetCommand, SetAssetPropertyCommand } from '../../src/core/commands/assetCommands';
import { AddNodeCommand, ConnectCommand } from '../../src/core/commands/graphCommands';
import {
AddNodeCommand,
CollapseNodesCommand,
ConnectCommand,
FoldEdgeCommand,
MoveNodeCommand,
SetNodeParamCommand,
} from '../../src/core/commands/graphCommands';
import { SetOverrideCommand } from '../../src/core/commands/sceneObjectCommands';
import type { Graph } from '../../src/core/graph';
import { BUILT_IN_NODES } from '../../src/core/graph/nodes';
@@ -27,7 +34,7 @@ import {
shaderParamDefs,
} from '../../src/core/properties/shaders';
import { inlineInputs } from '../../src/core/graph/NodeRegistry';
import { compileShader } from '../../src/core/shader/compile';
import { compileShader, shaderFingerprint } from '../../src/core/shader/compile';
import {
SHADER_NODES,
SHADER_NUMBER,
@@ -567,3 +574,22 @@ describe('a sprite wearing a shader', () => {
expect(shader.graph.nodes.map((n) => n.id)).toEqual(['o']);
});
});
describe('the fingerprint the shader library caches on', () => {
it('ignores a move, a collapse and a fold, and changes with a param or an edge', () => {
const f = makeProject();
const s = shaderEditor(f);
const n = buildAdjustColors(s);
const before = shaderFingerprint(s.asset().graph);
f.stack.execute(new MoveNodeCommand(s.id, n.bright, 300, 200));
f.stack.execute(new CollapseNodesCommand(s.id, [n.bright, n.luma], true));
f.stack.execute(new FoldEdgeCommand(s.id, s.asset().graph.edges[0]!.id, true));
expect(s.asset().graph.nodes.find((x) => x.id === n.bright)).toMatchObject({ x: 300, collapsed: true });
expect(shaderFingerprint(s.asset().graph)).toBe(before);
f.stack.execute(new SetNodeParamCommand(s.id, n.shifted, 'b', 0.25));
const withParam = shaderFingerprint(s.asset().graph);
expect(withParam).not.toBe(before);
s.link(n.brightness, 'value', n.output, 'alpha');
expect(shaderFingerprint(s.asset().graph)).not.toBe(withParam);
});
});