@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.
Files changed (78) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +184 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/graph-pass-kind-owner.test-d.d.ts +2 -0
  5. package/dist/__tests__/graph-pass-kind-owner.test-d.d.ts.map +1 -0
  6. package/dist/__tests__/observation-lifetime-state-owner.test-d.d.ts +2 -0
  7. package/dist/__tests__/observation-lifetime-state-owner.test-d.d.ts.map +1 -0
  8. package/dist/__tests__/observation.unit.test.d.ts +2 -0
  9. package/dist/__tests__/observation.unit.test.d.ts.map +1 -0
  10. package/dist/__tests__/render-graph-alias-source.unit.test.d.ts +2 -0
  11. package/dist/__tests__/render-graph-alias-source.unit.test.d.ts.map +1 -0
  12. package/dist/__tests__/render-graph-builder.unit.test.d.ts +2 -0
  13. package/dist/__tests__/render-graph-builder.unit.test.d.ts.map +1 -0
  14. package/dist/__tests__/render-graph-capability-owner.test-d.d.ts +2 -0
  15. package/dist/__tests__/render-graph-capability-owner.test-d.d.ts.map +1 -0
  16. package/dist/__tests__/render-graph-errors.test-d.d.ts +2 -0
  17. package/dist/__tests__/render-graph-errors.test-d.d.ts.map +1 -0
  18. package/dist/__tests__/render-graph-regressions.unit.test.d.ts +2 -0
  19. package/dist/__tests__/render-graph-regressions.unit.test.d.ts.map +1 -0
  20. package/dist/__tests__/render-graph-rhi-null.integration.test.d.ts +2 -0
  21. package/dist/__tests__/render-graph-rhi-null.integration.test.d.ts.map +1 -0
  22. package/dist/__tests__/render-graph.unit.test.d.ts +2 -0
  23. package/dist/__tests__/render-graph.unit.test.d.ts.map +1 -0
  24. package/dist/__tests__/resource-declaration-collision.test.d.ts +2 -0
  25. package/dist/__tests__/resource-declaration-collision.test.d.ts.map +1 -0
  26. package/dist/__tests__/resource-kind-owner.test-d.d.ts +2 -0
  27. package/dist/__tests__/resource-kind-owner.test-d.d.ts.map +1 -0
  28. package/dist/builder.d.ts +42 -0
  29. package/dist/builder.d.ts.map +1 -0
  30. package/dist/compiled-graph.d.ts +23 -0
  31. package/dist/compiled-graph.d.ts.map +1 -0
  32. package/dist/errors.d.ts +148 -0
  33. package/dist/errors.d.ts.map +1 -0
  34. package/dist/graph.d.ts +404 -0
  35. package/dist/graph.d.ts.map +1 -0
  36. package/dist/index.d.ts +8 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.mjs +2256 -0
  39. package/dist/index.mjs.map +1 -0
  40. package/dist/kernel-internal.d.ts +84 -0
  41. package/dist/kernel-internal.d.ts.map +1 -0
  42. package/dist/observation.d.ts +38 -0
  43. package/dist/observation.d.ts.map +1 -0
  44. package/dist/pass-registry.d.ts +12 -0
  45. package/dist/pass-registry.d.ts.map +1 -0
  46. package/dist/pipeline/__tests__/color-value-domain.test.d.ts +2 -0
  47. package/dist/pipeline/__tests__/color-value-domain.test.d.ts.map +1 -0
  48. package/dist/pipeline/color-value-domain.d.ts +35 -0
  49. package/dist/pipeline/color-value-domain.d.ts.map +1 -0
  50. package/dist/resource-registry.d.ts +61 -0
  51. package/dist/resource-registry.d.ts.map +1 -0
  52. package/dist/types.d.ts +171 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/package.json +61 -0
  55. package/src/__tests__/graph-pass-kind-owner.test-d.ts +35 -0
  56. package/src/__tests__/observation-lifetime-state-owner.test-d.ts +39 -0
  57. package/src/__tests__/observation.unit.test.ts +103 -0
  58. package/src/__tests__/render-graph-alias-source.unit.test.ts +118 -0
  59. package/src/__tests__/render-graph-builder.unit.test.ts +664 -0
  60. package/src/__tests__/render-graph-capability-owner.test-d.ts +32 -0
  61. package/src/__tests__/render-graph-errors.test-d.ts +169 -0
  62. package/src/__tests__/render-graph-regressions.unit.test.ts +126 -0
  63. package/src/__tests__/render-graph-rhi-null.integration.test.ts +86 -0
  64. package/src/__tests__/render-graph.unit.test.ts +2549 -0
  65. package/src/__tests__/resource-declaration-collision.test.ts +151 -0
  66. package/src/__tests__/resource-kind-owner.test-d.ts +38 -0
  67. package/src/builder.ts +1009 -0
  68. package/src/compiled-graph.ts +383 -0
  69. package/src/errors.ts +205 -0
  70. package/src/graph.ts +1270 -0
  71. package/src/index.ts +97 -0
  72. package/src/kernel-internal.ts +148 -0
  73. package/src/observation.ts +134 -0
  74. package/src/pass-registry.ts +43 -0
  75. package/src/pipeline/__tests__/color-value-domain.test.ts +43 -0
  76. package/src/pipeline/color-value-domain.ts +139 -0
  77. package/src/resource-registry.ts +173 -0
  78. 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
+ });