@motion-core/motion-gpu 0.1.0

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +325 -0
  3. package/dist/FragCanvas.svelte +511 -0
  4. package/dist/FragCanvas.svelte.d.ts +26 -0
  5. package/dist/MotionGPUErrorOverlay.svelte +394 -0
  6. package/dist/MotionGPUErrorOverlay.svelte.d.ts +7 -0
  7. package/dist/Portal.svelte +46 -0
  8. package/dist/Portal.svelte.d.ts +8 -0
  9. package/dist/advanced-scheduler.d.ts +44 -0
  10. package/dist/advanced-scheduler.js +58 -0
  11. package/dist/advanced.d.ts +14 -0
  12. package/dist/advanced.js +9 -0
  13. package/dist/core/error-diagnostics.d.ts +40 -0
  14. package/dist/core/error-diagnostics.js +111 -0
  15. package/dist/core/error-report.d.ts +67 -0
  16. package/dist/core/error-report.js +190 -0
  17. package/dist/core/material-preprocess.d.ts +63 -0
  18. package/dist/core/material-preprocess.js +166 -0
  19. package/dist/core/material.d.ts +157 -0
  20. package/dist/core/material.js +358 -0
  21. package/dist/core/recompile-policy.d.ts +27 -0
  22. package/dist/core/recompile-policy.js +15 -0
  23. package/dist/core/render-graph.d.ts +55 -0
  24. package/dist/core/render-graph.js +73 -0
  25. package/dist/core/render-targets.d.ts +39 -0
  26. package/dist/core/render-targets.js +63 -0
  27. package/dist/core/renderer.d.ts +9 -0
  28. package/dist/core/renderer.js +1097 -0
  29. package/dist/core/shader.d.ts +42 -0
  30. package/dist/core/shader.js +196 -0
  31. package/dist/core/texture-loader.d.ts +129 -0
  32. package/dist/core/texture-loader.js +295 -0
  33. package/dist/core/textures.d.ts +114 -0
  34. package/dist/core/textures.js +136 -0
  35. package/dist/core/types.d.ts +523 -0
  36. package/dist/core/types.js +4 -0
  37. package/dist/core/uniforms.d.ts +48 -0
  38. package/dist/core/uniforms.js +222 -0
  39. package/dist/current-writable.d.ts +31 -0
  40. package/dist/current-writable.js +27 -0
  41. package/dist/frame-context.d.ts +287 -0
  42. package/dist/frame-context.js +731 -0
  43. package/dist/index.d.ts +17 -0
  44. package/dist/index.js +11 -0
  45. package/dist/motiongpu-context.d.ts +77 -0
  46. package/dist/motiongpu-context.js +26 -0
  47. package/dist/passes/BlitPass.d.ts +32 -0
  48. package/dist/passes/BlitPass.js +158 -0
  49. package/dist/passes/CopyPass.d.ts +25 -0
  50. package/dist/passes/CopyPass.js +53 -0
  51. package/dist/passes/ShaderPass.d.ts +40 -0
  52. package/dist/passes/ShaderPass.js +182 -0
  53. package/dist/passes/index.d.ts +3 -0
  54. package/dist/passes/index.js +3 -0
  55. package/dist/use-motiongpu-user-context.d.ts +35 -0
  56. package/dist/use-motiongpu-user-context.js +74 -0
  57. package/dist/use-texture.d.ts +35 -0
  58. package/dist/use-texture.js +147 -0
  59. package/package.json +94 -0
@@ -0,0 +1,114 @@
1
+ import type { TextureData, TextureDefinition, TextureDefinitionMap, TextureUpdateMode, TextureValue } from './types';
2
+ /**
3
+ * Texture definition with defaults and normalized numeric limits applied.
4
+ */
5
+ export interface NormalizedTextureDefinition {
6
+ /**
7
+ * Normalized source value.
8
+ */
9
+ source: TextureValue;
10
+ /**
11
+ * Effective color space.
12
+ */
13
+ colorSpace: 'srgb' | 'linear';
14
+ /**
15
+ * Effective texture format.
16
+ */
17
+ format: GPUTextureFormat;
18
+ /**
19
+ * Effective flip-y flag.
20
+ */
21
+ flipY: boolean;
22
+ /**
23
+ * Effective mipmap toggle.
24
+ */
25
+ generateMipmaps: boolean;
26
+ /**
27
+ * Effective premultiplied-alpha flag.
28
+ */
29
+ premultipliedAlpha: boolean;
30
+ /**
31
+ * Effective dynamic update strategy.
32
+ */
33
+ update?: TextureUpdateMode;
34
+ /**
35
+ * Effective anisotropy level.
36
+ */
37
+ anisotropy: number;
38
+ /**
39
+ * Effective filter mode.
40
+ */
41
+ filter: GPUFilterMode;
42
+ /**
43
+ * Effective U address mode.
44
+ */
45
+ addressModeU: GPUAddressMode;
46
+ /**
47
+ * Effective V address mode.
48
+ */
49
+ addressModeV: GPUAddressMode;
50
+ }
51
+ /**
52
+ * Validates and returns sorted texture keys.
53
+ *
54
+ * @param textures - Texture definition map.
55
+ * @returns Lexicographically sorted texture keys.
56
+ */
57
+ export declare function resolveTextureKeys(textures: TextureDefinitionMap): string[];
58
+ /**
59
+ * Applies defaults and clamps to a single texture definition.
60
+ *
61
+ * @param definition - Optional texture definition.
62
+ * @returns Normalized definition with deterministic defaults.
63
+ */
64
+ export declare function normalizeTextureDefinition(definition: TextureDefinition | undefined): NormalizedTextureDefinition;
65
+ /**
66
+ * Normalizes all texture definitions for already-resolved texture keys.
67
+ *
68
+ * @param textures - Source texture definitions.
69
+ * @param textureKeys - Texture keys to normalize.
70
+ * @returns Normalized map keyed by `textureKeys`.
71
+ */
72
+ export declare function normalizeTextureDefinitions(textures: TextureDefinitionMap, textureKeys: string[]): Record<string, NormalizedTextureDefinition>;
73
+ /**
74
+ * Checks whether a texture value is a structured `{ source, width?, height? }` object.
75
+ */
76
+ export declare function isTextureData(value: TextureValue): value is TextureData;
77
+ /**
78
+ * Converts supported texture input variants to normalized `TextureData`.
79
+ *
80
+ * @param value - Texture value input.
81
+ * @returns Structured texture data or `null`.
82
+ */
83
+ export declare function toTextureData(value: TextureValue): TextureData | null;
84
+ /**
85
+ * Resolves effective runtime texture update strategy.
86
+ */
87
+ export declare function resolveTextureUpdateMode(input: {
88
+ source: TextureData['source'];
89
+ override?: TextureUpdateMode;
90
+ defaultMode?: TextureUpdateMode;
91
+ }): TextureUpdateMode;
92
+ /**
93
+ * Resolves texture dimensions from explicit values or source metadata.
94
+ *
95
+ * @param data - Texture payload.
96
+ * @returns Positive integer width/height.
97
+ * @throws {Error} When dimensions cannot be resolved to positive values.
98
+ */
99
+ export declare function resolveTextureSize(data: TextureData): {
100
+ width: number;
101
+ height: number;
102
+ };
103
+ /**
104
+ * Computes the number of mipmap levels for a base texture size.
105
+ *
106
+ * @param width - Base width.
107
+ * @param height - Base height.
108
+ * @returns Total mip level count (minimum `1`).
109
+ */
110
+ export declare function getTextureMipLevelCount(width: number, height: number): number;
111
+ /**
112
+ * Checks whether the source is an `HTMLVideoElement`.
113
+ */
114
+ export declare function isVideoTextureSource(source: TextureData['source']): source is HTMLVideoElement;
@@ -0,0 +1,136 @@
1
+ import { assertUniformName } from './uniforms';
2
+ /**
3
+ * Default sampling filter for textures when no explicit value is provided.
4
+ */
5
+ const DEFAULT_TEXTURE_FILTER = 'linear';
6
+ /**
7
+ * Default addressing mode for textures when no explicit value is provided.
8
+ */
9
+ const DEFAULT_TEXTURE_ADDRESS_MODE = 'clamp-to-edge';
10
+ /**
11
+ * Validates and returns sorted texture keys.
12
+ *
13
+ * @param textures - Texture definition map.
14
+ * @returns Lexicographically sorted texture keys.
15
+ */
16
+ export function resolveTextureKeys(textures) {
17
+ const keys = Object.keys(textures).sort();
18
+ for (const key of keys) {
19
+ assertUniformName(key);
20
+ }
21
+ return keys;
22
+ }
23
+ /**
24
+ * Applies defaults and clamps to a single texture definition.
25
+ *
26
+ * @param definition - Optional texture definition.
27
+ * @returns Normalized definition with deterministic defaults.
28
+ */
29
+ export function normalizeTextureDefinition(definition) {
30
+ const normalized = {
31
+ source: definition?.source ?? null,
32
+ colorSpace: definition?.colorSpace ?? 'srgb',
33
+ format: definition?.colorSpace === 'linear' ? 'rgba8unorm' : 'rgba8unorm-srgb',
34
+ flipY: definition?.flipY ?? true,
35
+ generateMipmaps: definition?.generateMipmaps ?? false,
36
+ premultipliedAlpha: definition?.premultipliedAlpha ?? false,
37
+ anisotropy: Math.max(1, Math.min(16, Math.floor(definition?.anisotropy ?? 1))),
38
+ filter: definition?.filter ?? DEFAULT_TEXTURE_FILTER,
39
+ addressModeU: definition?.addressModeU ?? DEFAULT_TEXTURE_ADDRESS_MODE,
40
+ addressModeV: definition?.addressModeV ?? DEFAULT_TEXTURE_ADDRESS_MODE
41
+ };
42
+ if (definition?.update !== undefined) {
43
+ normalized.update = definition.update;
44
+ }
45
+ return normalized;
46
+ }
47
+ /**
48
+ * Normalizes all texture definitions for already-resolved texture keys.
49
+ *
50
+ * @param textures - Source texture definitions.
51
+ * @param textureKeys - Texture keys to normalize.
52
+ * @returns Normalized map keyed by `textureKeys`.
53
+ */
54
+ export function normalizeTextureDefinitions(textures, textureKeys) {
55
+ const out = {};
56
+ for (const key of textureKeys) {
57
+ out[key] = normalizeTextureDefinition(textures[key]);
58
+ }
59
+ return out;
60
+ }
61
+ /**
62
+ * Checks whether a texture value is a structured `{ source, width?, height? }` object.
63
+ */
64
+ export function isTextureData(value) {
65
+ return typeof value === 'object' && value !== null && 'source' in value;
66
+ }
67
+ /**
68
+ * Converts supported texture input variants to normalized `TextureData`.
69
+ *
70
+ * @param value - Texture value input.
71
+ * @returns Structured texture data or `null`.
72
+ */
73
+ export function toTextureData(value) {
74
+ if (value === null) {
75
+ return null;
76
+ }
77
+ if (isTextureData(value)) {
78
+ return value;
79
+ }
80
+ return { source: value };
81
+ }
82
+ /**
83
+ * Resolves effective runtime texture update strategy.
84
+ */
85
+ export function resolveTextureUpdateMode(input) {
86
+ if (input.override) {
87
+ return input.override;
88
+ }
89
+ if (input.defaultMode) {
90
+ return input.defaultMode;
91
+ }
92
+ if (isVideoTextureSource(input.source)) {
93
+ return 'perFrame';
94
+ }
95
+ return 'once';
96
+ }
97
+ /**
98
+ * Resolves texture dimensions from explicit values or source metadata.
99
+ *
100
+ * @param data - Texture payload.
101
+ * @returns Positive integer width/height.
102
+ * @throws {Error} When dimensions cannot be resolved to positive values.
103
+ */
104
+ export function resolveTextureSize(data) {
105
+ const source = data.source;
106
+ const width = data.width ?? source.naturalWidth ?? source.videoWidth ?? source.width ?? 0;
107
+ const height = data.height ?? source.naturalHeight ?? source.videoHeight ?? source.height ?? 0;
108
+ if (width <= 0 || height <= 0) {
109
+ throw new Error('Texture source must have positive width and height');
110
+ }
111
+ return { width, height };
112
+ }
113
+ /**
114
+ * Computes the number of mipmap levels for a base texture size.
115
+ *
116
+ * @param width - Base width.
117
+ * @param height - Base height.
118
+ * @returns Total mip level count (minimum `1`).
119
+ */
120
+ export function getTextureMipLevelCount(width, height) {
121
+ let levels = 1;
122
+ let currentWidth = Math.max(1, width);
123
+ let currentHeight = Math.max(1, height);
124
+ while (currentWidth > 1 || currentHeight > 1) {
125
+ currentWidth = Math.max(1, Math.floor(currentWidth / 2));
126
+ currentHeight = Math.max(1, Math.floor(currentHeight / 2));
127
+ levels += 1;
128
+ }
129
+ return levels;
130
+ }
131
+ /**
132
+ * Checks whether the source is an `HTMLVideoElement`.
133
+ */
134
+ export function isVideoTextureSource(source) {
135
+ return typeof HTMLVideoElement !== 'undefined' && source instanceof HTMLVideoElement;
136
+ }