@forgeax/engine-render-graph 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +184 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/graph-pass-kind-owner.test-d.d.ts +2 -0
- package/dist/__tests__/graph-pass-kind-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/observation-lifetime-state-owner.test-d.d.ts +2 -0
- package/dist/__tests__/observation-lifetime-state-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/observation.unit.test.d.ts +2 -0
- package/dist/__tests__/observation.unit.test.d.ts.map +1 -0
- package/dist/__tests__/render-graph-alias-source.unit.test.d.ts +2 -0
- package/dist/__tests__/render-graph-alias-source.unit.test.d.ts.map +1 -0
- package/dist/__tests__/render-graph-builder.unit.test.d.ts +2 -0
- package/dist/__tests__/render-graph-builder.unit.test.d.ts.map +1 -0
- package/dist/__tests__/render-graph-capability-owner.test-d.d.ts +2 -0
- package/dist/__tests__/render-graph-capability-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/render-graph-errors.test-d.d.ts +2 -0
- package/dist/__tests__/render-graph-errors.test-d.d.ts.map +1 -0
- package/dist/__tests__/render-graph-regressions.unit.test.d.ts +2 -0
- package/dist/__tests__/render-graph-regressions.unit.test.d.ts.map +1 -0
- package/dist/__tests__/render-graph-rhi-null.integration.test.d.ts +2 -0
- package/dist/__tests__/render-graph-rhi-null.integration.test.d.ts.map +1 -0
- package/dist/__tests__/render-graph.unit.test.d.ts +2 -0
- package/dist/__tests__/render-graph.unit.test.d.ts.map +1 -0
- package/dist/__tests__/resource-declaration-collision.test.d.ts +2 -0
- package/dist/__tests__/resource-declaration-collision.test.d.ts.map +1 -0
- package/dist/__tests__/resource-kind-owner.test-d.d.ts +2 -0
- package/dist/__tests__/resource-kind-owner.test-d.d.ts.map +1 -0
- package/dist/builder.d.ts +42 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/compiled-graph.d.ts +23 -0
- package/dist/compiled-graph.d.ts.map +1 -0
- package/dist/errors.d.ts +148 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/graph.d.ts +404 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +2256 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kernel-internal.d.ts +84 -0
- package/dist/kernel-internal.d.ts.map +1 -0
- package/dist/observation.d.ts +38 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/pass-registry.d.ts +12 -0
- package/dist/pass-registry.d.ts.map +1 -0
- package/dist/pipeline/__tests__/color-value-domain.test.d.ts +2 -0
- package/dist/pipeline/__tests__/color-value-domain.test.d.ts.map +1 -0
- package/dist/pipeline/color-value-domain.d.ts +35 -0
- package/dist/pipeline/color-value-domain.d.ts.map +1 -0
- package/dist/resource-registry.d.ts +61 -0
- package/dist/resource-registry.d.ts.map +1 -0
- package/dist/types.d.ts +171 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +61 -0
- package/src/__tests__/graph-pass-kind-owner.test-d.ts +35 -0
- package/src/__tests__/observation-lifetime-state-owner.test-d.ts +39 -0
- package/src/__tests__/observation.unit.test.ts +103 -0
- package/src/__tests__/render-graph-alias-source.unit.test.ts +118 -0
- package/src/__tests__/render-graph-builder.unit.test.ts +664 -0
- package/src/__tests__/render-graph-capability-owner.test-d.ts +32 -0
- package/src/__tests__/render-graph-errors.test-d.ts +169 -0
- package/src/__tests__/render-graph-regressions.unit.test.ts +126 -0
- package/src/__tests__/render-graph-rhi-null.integration.test.ts +86 -0
- package/src/__tests__/render-graph.unit.test.ts +2549 -0
- package/src/__tests__/resource-declaration-collision.test.ts +151 -0
- package/src/__tests__/resource-kind-owner.test-d.ts +38 -0
- package/src/builder.ts +1009 -0
- package/src/compiled-graph.ts +383 -0
- package/src/errors.ts +205 -0
- package/src/graph.ts +1270 -0
- package/src/index.ts +97 -0
- package/src/kernel-internal.ts +148 -0
- package/src/observation.ts +134 -0
- package/src/pass-registry.ts +43 -0
- package/src/pipeline/__tests__/color-value-domain.test.ts +43 -0
- package/src/pipeline/color-value-domain.ts +139 -0
- package/src/resource-registry.ts +173 -0
- package/src/types.ts +217 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { RenderGraph } from '../graph.js';
|
|
3
|
+
|
|
4
|
+
const colorTarget = {
|
|
5
|
+
format: 'rgba8unorm',
|
|
6
|
+
size: { w: 4, h: 4 },
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
function makeDevice(): {
|
|
10
|
+
readonly device: object;
|
|
11
|
+
readonly created: object[];
|
|
12
|
+
readonly destroyed: object[];
|
|
13
|
+
} {
|
|
14
|
+
const created: object[] = [];
|
|
15
|
+
const destroyed: object[] = [];
|
|
16
|
+
const device = {
|
|
17
|
+
createTexture: () => {
|
|
18
|
+
const texture = { id: `texture-${created.length + 1}` };
|
|
19
|
+
created.push(texture);
|
|
20
|
+
return { ok: true as const, value: texture };
|
|
21
|
+
},
|
|
22
|
+
createTextureView: (texture: object) => ({
|
|
23
|
+
ok: true as const,
|
|
24
|
+
value: { texture },
|
|
25
|
+
}),
|
|
26
|
+
destroyTexture: (texture: object) => {
|
|
27
|
+
destroyed.push(texture);
|
|
28
|
+
return { ok: true as const, value: undefined };
|
|
29
|
+
},
|
|
30
|
+
queue: { onSubmittedWorkDone: () => Promise.resolve(undefined) },
|
|
31
|
+
};
|
|
32
|
+
return { device, created, destroyed };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const compileOptions = {
|
|
36
|
+
backendKind: 'webgpu' as const,
|
|
37
|
+
caps: { backendKind: 'webgpu', compute: true, storageBuffer: true } as never,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe('RenderGraph alias-source refusal and recovery', () => {
|
|
41
|
+
it('refuses an absent source without mutation, then repairs on the same graph', () => {
|
|
42
|
+
const graph = new RenderGraph();
|
|
43
|
+
const { device, created, destroyed } = makeDevice();
|
|
44
|
+
const executed: string[] = [];
|
|
45
|
+
|
|
46
|
+
expect(graph.addColorTarget('active', colorTarget).ok).toBe(true);
|
|
47
|
+
expect(graph.addColorTarget('sibling', colorTarget).ok).toBe(true);
|
|
48
|
+
graph.addPass('active-pass', {
|
|
49
|
+
reads: [],
|
|
50
|
+
writes: ['active'],
|
|
51
|
+
execute: () => executed.push('active-pass'),
|
|
52
|
+
});
|
|
53
|
+
graph.addPass('sibling-pass', {
|
|
54
|
+
reads: [],
|
|
55
|
+
writes: ['sibling'],
|
|
56
|
+
execute: () => executed.push('sibling-pass'),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(graph.compile({ ...compileOptions, device: device as never }).ok).toBe(true);
|
|
60
|
+
const initialResources = graph.listResources();
|
|
61
|
+
const initialPasses = graph.listPasses();
|
|
62
|
+
const initialActiveTexture = graph.getColorTargetTexture('active');
|
|
63
|
+
const initialSiblingTexture = graph.getColorTargetTexture('sibling');
|
|
64
|
+
const initialCreatedCount = created.length;
|
|
65
|
+
|
|
66
|
+
const refused = graph.addColorTargetAlias('alias', 'missing-source');
|
|
67
|
+
expect(refused.ok).toBe(false);
|
|
68
|
+
if (refused.ok) throw new Error('expected an absent alias source to be refused');
|
|
69
|
+
expect(refused.error.code).toBe('alias-source-missing');
|
|
70
|
+
expect(refused.error.detail).toEqual({
|
|
71
|
+
aliasKey: 'alias',
|
|
72
|
+
sourceKey: 'missing-source',
|
|
73
|
+
});
|
|
74
|
+
expect(graph.listResources()).toEqual(initialResources);
|
|
75
|
+
expect(graph.listPasses()).toEqual(initialPasses);
|
|
76
|
+
expect(graph.getColorTargetTexture('alias')).toBeUndefined();
|
|
77
|
+
expect(graph.getColorTargetView('alias')).toBeUndefined();
|
|
78
|
+
expect(created).toHaveLength(initialCreatedCount);
|
|
79
|
+
|
|
80
|
+
graph.execute(undefined);
|
|
81
|
+
expect(executed).toEqual(['active-pass', 'sibling-pass']);
|
|
82
|
+
|
|
83
|
+
expect(graph.addColorTarget('source', colorTarget).ok).toBe(true);
|
|
84
|
+
expect(graph.addColorTargetAlias('alias', 'source').ok).toBe(true);
|
|
85
|
+
graph.addPass('source-pass', {
|
|
86
|
+
reads: [],
|
|
87
|
+
writes: ['source'],
|
|
88
|
+
execute: () => executed.push('source-pass'),
|
|
89
|
+
});
|
|
90
|
+
graph.addPass('alias-pass', {
|
|
91
|
+
reads: ['source'],
|
|
92
|
+
writes: ['alias'],
|
|
93
|
+
execute: () => executed.push('alias-pass'),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const repaired = graph.compile({ ...compileOptions, device: device as never });
|
|
97
|
+
expect(repaired.ok).toBe(true);
|
|
98
|
+
expect(graph.getColorTargetTexture('active')).toBe(initialActiveTexture);
|
|
99
|
+
expect(graph.getColorTargetTexture('sibling')).toBe(initialSiblingTexture);
|
|
100
|
+
expect(graph.getColorTargetTexture('alias')).toBe(graph.getColorTargetTexture('source'));
|
|
101
|
+
expect(graph.getColorTargetView('alias')).toBe(graph.getColorTargetView('source'));
|
|
102
|
+
|
|
103
|
+
graph.execute(undefined);
|
|
104
|
+
expect(executed).toEqual([
|
|
105
|
+
'active-pass',
|
|
106
|
+
'sibling-pass',
|
|
107
|
+
'active-pass',
|
|
108
|
+
'sibling-pass',
|
|
109
|
+
'source-pass',
|
|
110
|
+
'alias-pass',
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
graph.drain();
|
|
114
|
+
graph.drain();
|
|
115
|
+
expect(destroyed).toHaveLength(created.length);
|
|
116
|
+
expect(new Set(destroyed)).toEqual(new Set(created));
|
|
117
|
+
});
|
|
118
|
+
});
|