typegpu 0.0.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ import { Parsed, ISchema } from 'typed-binary';
2
+
3
+ /**
4
+ * Helpful when creating new Resolvable types. For internal use.
5
+ */
6
+ declare class WgslIdentifier implements WgslResolvable {
7
+ label?: string | undefined;
8
+ $name(label: string | undefined): this;
9
+ resolve(ctx: ResolutionCtx): string;
10
+ toString(): string;
11
+ }
12
+
13
+ declare const WgslSettableTrait: unique symbol;
14
+ interface WgslSettable {
15
+ readonly [WgslSettableTrait]: true;
16
+ }
17
+
18
+ type Getter = <T>(plum: WgslPlum<T>) => T;
19
+ type Unsubscribe = () => unknown;
20
+ type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
21
+ interface WgslPlum<TValue = unknown> {
22
+ readonly __brand: 'WgslPlum';
23
+ $name(label: string): this;
24
+ /**
25
+ * Computes the value of this plum. Circumvents the store
26
+ * memoization, so use with care.
27
+ */
28
+ compute(get: Getter): TValue;
29
+ }
30
+ declare const WgslExternalPlumTrait: unique symbol;
31
+ interface WgslExternalPlum {
32
+ readonly [WgslExternalPlumTrait]: true;
33
+ readonly version: number;
34
+ subscribe(listener: () => unknown): Unsubscribe;
35
+ }
36
+ /**
37
+ * Creates a computed plum. Its value depends on the plums read using `get`
38
+ * inside the `compute` function, so cannot be set imperatively.
39
+ *
40
+ * @param compute A pure function that describes this plum's value.
41
+ */
42
+ declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
43
+ /**
44
+ * Creates a computed plum. Its value depends on the plums read using `get`
45
+ * inside the `compute` function, so cannot be set imperatively.
46
+ *
47
+ * @param compute A pure function that describes this plum's value.
48
+ */
49
+ declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
50
+ /**
51
+ * Creates a plum with an initial value of `initial`.
52
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
53
+ *
54
+ * @param initial The initial value of this plum.
55
+ */
56
+ declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
57
+ /**
58
+ * Creates a plum with an initial value of `initial`.
59
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
60
+ *
61
+ * @param initial The initial value of this plum.
62
+ */
63
+ declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
64
+ declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
65
+
66
+ type Wgsl = string | boolean | number | WgslResolvable;
67
+ /**
68
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
69
+ * and a new resolution ctx is made when going down each level in the tree.
70
+ */
71
+ interface ResolutionCtx {
72
+ /**
73
+ * Slots that were used by items resolved by this context.
74
+ */
75
+ readonly usedSlots: Iterable<WgslSlot<unknown>>;
76
+ addDeclaration(item: WgslResolvable): void;
77
+ addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
78
+ nameFor(token: WgslResolvable): string;
79
+ /**
80
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
81
+ * @throws {MissingSlotValueError}
82
+ */
83
+ unwrap<T>(eventual: Eventual<T>): T;
84
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
85
+ }
86
+ interface WgslResolvable {
87
+ readonly label?: string | undefined;
88
+ resolve(ctx: ResolutionCtx): string;
89
+ }
90
+ declare function isResolvable(value: unknown): value is WgslResolvable;
91
+ declare function isWgsl(value: unknown): value is Wgsl;
92
+ interface WgslSlot<T> {
93
+ readonly __brand: 'WgslSlot';
94
+ readonly defaultValue: T | undefined;
95
+ readonly label?: string | undefined;
96
+ $name(label: string): WgslSlot<T>;
97
+ /**
98
+ * Used to determine if code generated using either value `a` or `b` in place
99
+ * of the slot will be equivalent. Defaults to `Object.is`.
100
+ */
101
+ areEqual(a: T, b: T): boolean;
102
+ }
103
+ declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
104
+ /**
105
+ * Represents a value that is available at resolution time.
106
+ */
107
+ type Eventual<T> = T | WgslSlot<T>;
108
+ type EventualGetter = <T>(value: Eventual<T>) => T;
109
+ type InlineResolve = (get: EventualGetter) => Wgsl;
110
+ interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
111
+ $name(label: string): WgslResolvableSlot<T>;
112
+ }
113
+ type SlotValuePair<T> = [WgslSlot<T>, T];
114
+ interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
115
+ /**
116
+ * The data type this allocatable was constructed with.
117
+ * It informs the size and format of data in both JS and
118
+ * binary.
119
+ */
120
+ readonly dataType: TData;
121
+ readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
122
+ readonly flags: GPUBufferUsageFlags;
123
+ }
124
+ interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
125
+ readonly allocatable: WgslAllocatable<TData>;
126
+ readonly usage: TUsage;
127
+ }
128
+ type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';
129
+ interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
130
+ readonly byteAlignment: number;
131
+ readonly size: number;
132
+ }
133
+ type AnyWgslData = WgslData<unknown>;
134
+ interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
135
+ readonly scope: TScope;
136
+ readonly pointsTo: TInner;
137
+ }
138
+ /**
139
+ * A virtual representation of a WGSL value.
140
+ */
141
+ type WgslValue<TDataType> = {
142
+ readonly __dataType: TDataType;
143
+ };
144
+ type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
145
+ type WgslFnArgument = AnyWgslPointer | AnyWgslData;
146
+ declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
147
+
148
+ export { type AnyWgslData as A, type BufferUsage as B, type ExtractPlumValue as E, type InlineResolve as I, type ResolutionCtx as R, type SlotValuePair as S, type Unsubscribe as U, type WgslSlot as W, type WgslResolvable as a, type Wgsl as b, type WgslPlum as c, type WgslSettable as d, type WgslAllocatable as e, type WgslBindable as f, type Eventual as g, type WgslFnArgument as h, type WgslValue as i, WgslIdentifier as j, type WgslResolvableSlot as k, plumFromEvent as l, isResolvable as m, isWgsl as n, isSlot as o, plum as p, type EventualGetter as q, type WgslData as r, type WgslPointer as s, type AnyWgslPointer as t, isPointer as u };
@@ -0,0 +1,148 @@
1
+ import { Parsed, ISchema } from 'typed-binary';
2
+
3
+ /**
4
+ * Helpful when creating new Resolvable types. For internal use.
5
+ */
6
+ declare class WgslIdentifier implements WgslResolvable {
7
+ label?: string | undefined;
8
+ $name(label: string | undefined): this;
9
+ resolve(ctx: ResolutionCtx): string;
10
+ toString(): string;
11
+ }
12
+
13
+ declare const WgslSettableTrait: unique symbol;
14
+ interface WgslSettable {
15
+ readonly [WgslSettableTrait]: true;
16
+ }
17
+
18
+ type Getter = <T>(plum: WgslPlum<T>) => T;
19
+ type Unsubscribe = () => unknown;
20
+ type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
21
+ interface WgslPlum<TValue = unknown> {
22
+ readonly __brand: 'WgslPlum';
23
+ $name(label: string): this;
24
+ /**
25
+ * Computes the value of this plum. Circumvents the store
26
+ * memoization, so use with care.
27
+ */
28
+ compute(get: Getter): TValue;
29
+ }
30
+ declare const WgslExternalPlumTrait: unique symbol;
31
+ interface WgslExternalPlum {
32
+ readonly [WgslExternalPlumTrait]: true;
33
+ readonly version: number;
34
+ subscribe(listener: () => unknown): Unsubscribe;
35
+ }
36
+ /**
37
+ * Creates a computed plum. Its value depends on the plums read using `get`
38
+ * inside the `compute` function, so cannot be set imperatively.
39
+ *
40
+ * @param compute A pure function that describes this plum's value.
41
+ */
42
+ declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
43
+ /**
44
+ * Creates a computed plum. Its value depends on the plums read using `get`
45
+ * inside the `compute` function, so cannot be set imperatively.
46
+ *
47
+ * @param compute A pure function that describes this plum's value.
48
+ */
49
+ declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
50
+ /**
51
+ * Creates a plum with an initial value of `initial`.
52
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
53
+ *
54
+ * @param initial The initial value of this plum.
55
+ */
56
+ declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
57
+ /**
58
+ * Creates a plum with an initial value of `initial`.
59
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
60
+ *
61
+ * @param initial The initial value of this plum.
62
+ */
63
+ declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
64
+ declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
65
+
66
+ type Wgsl = string | boolean | number | WgslResolvable;
67
+ /**
68
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
69
+ * and a new resolution ctx is made when going down each level in the tree.
70
+ */
71
+ interface ResolutionCtx {
72
+ /**
73
+ * Slots that were used by items resolved by this context.
74
+ */
75
+ readonly usedSlots: Iterable<WgslSlot<unknown>>;
76
+ addDeclaration(item: WgslResolvable): void;
77
+ addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
78
+ nameFor(token: WgslResolvable): string;
79
+ /**
80
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
81
+ * @throws {MissingSlotValueError}
82
+ */
83
+ unwrap<T>(eventual: Eventual<T>): T;
84
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
85
+ }
86
+ interface WgslResolvable {
87
+ readonly label?: string | undefined;
88
+ resolve(ctx: ResolutionCtx): string;
89
+ }
90
+ declare function isResolvable(value: unknown): value is WgslResolvable;
91
+ declare function isWgsl(value: unknown): value is Wgsl;
92
+ interface WgslSlot<T> {
93
+ readonly __brand: 'WgslSlot';
94
+ readonly defaultValue: T | undefined;
95
+ readonly label?: string | undefined;
96
+ $name(label: string): WgslSlot<T>;
97
+ /**
98
+ * Used to determine if code generated using either value `a` or `b` in place
99
+ * of the slot will be equivalent. Defaults to `Object.is`.
100
+ */
101
+ areEqual(a: T, b: T): boolean;
102
+ }
103
+ declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
104
+ /**
105
+ * Represents a value that is available at resolution time.
106
+ */
107
+ type Eventual<T> = T | WgslSlot<T>;
108
+ type EventualGetter = <T>(value: Eventual<T>) => T;
109
+ type InlineResolve = (get: EventualGetter) => Wgsl;
110
+ interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
111
+ $name(label: string): WgslResolvableSlot<T>;
112
+ }
113
+ type SlotValuePair<T> = [WgslSlot<T>, T];
114
+ interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
115
+ /**
116
+ * The data type this allocatable was constructed with.
117
+ * It informs the size and format of data in both JS and
118
+ * binary.
119
+ */
120
+ readonly dataType: TData;
121
+ readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
122
+ readonly flags: GPUBufferUsageFlags;
123
+ }
124
+ interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
125
+ readonly allocatable: WgslAllocatable<TData>;
126
+ readonly usage: TUsage;
127
+ }
128
+ type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';
129
+ interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
130
+ readonly byteAlignment: number;
131
+ readonly size: number;
132
+ }
133
+ type AnyWgslData = WgslData<unknown>;
134
+ interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
135
+ readonly scope: TScope;
136
+ readonly pointsTo: TInner;
137
+ }
138
+ /**
139
+ * A virtual representation of a WGSL value.
140
+ */
141
+ type WgslValue<TDataType> = {
142
+ readonly __dataType: TDataType;
143
+ };
144
+ type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
145
+ type WgslFnArgument = AnyWgslPointer | AnyWgslData;
146
+ declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
147
+
148
+ export { type AnyWgslData as A, type BufferUsage as B, type ExtractPlumValue as E, type InlineResolve as I, type ResolutionCtx as R, type SlotValuePair as S, type Unsubscribe as U, type WgslSlot as W, type WgslResolvable as a, type Wgsl as b, type WgslPlum as c, type WgslSettable as d, type WgslAllocatable as e, type WgslBindable as f, type Eventual as g, type WgslFnArgument as h, type WgslValue as i, WgslIdentifier as j, type WgslResolvableSlot as k, plumFromEvent as l, isResolvable as m, isWgsl as n, isSlot as o, plum as p, type EventualGetter as q, type WgslData as r, type WgslPointer as s, type AnyWgslPointer as t, isPointer as u };
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "typegpu",
3
+ "version": "0.0.0-alpha.1",
4
+ "description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "module": "./dist/index.js",
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.cjs"
16
+ },
17
+ "./*": {
18
+ "types": "./*.d.ts",
19
+ "module": "./dist/*.js",
20
+ "import": "./dist/*.js",
21
+ "default": "./dist/*.cjs"
22
+ },
23
+ "./data": {
24
+ "types": "./dist/data/index.d.ts",
25
+ "module": "./dist/data/index.js",
26
+ "import": "./dist/data/index.js",
27
+ "default": "./dist/data/index.cjs"
28
+ },
29
+ "./macro": {
30
+ "types": "./dist/macro/index.d.ts",
31
+ "module": "./dist/macro/index.js",
32
+ "import": "./dist/macro/index.js",
33
+ "default": "./dist/macro/index.cjs"
34
+ },
35
+ "./web": {
36
+ "types": "./dist/web/index.d.ts",
37
+ "module": "./dist/web/index.js",
38
+ "import": "./dist/web/index.js",
39
+ "default": "./dist/web/index.cjs"
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "sideEffects": false,
47
+ "engines": {
48
+ "node": ">=12.20.0"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/software-mansion/typegpu.git"
53
+ },
54
+ "keywords": [
55
+ "webgpu",
56
+ "wgpu",
57
+ "wgsl",
58
+ "typescript",
59
+ "compute",
60
+ "shader",
61
+ "shaders",
62
+ "gpgpu"
63
+ ],
64
+ "bugs": {
65
+ "url": "https://github.com/software-mansion/typegpu/issues"
66
+ },
67
+ "homepage": "https://github.com/software-mansion/typegpu",
68
+ "devDependencies": {
69
+ "tsup": "^8.0.2",
70
+ "typescript": "^5.3.3",
71
+ "typed-binary": "^4.0.0",
72
+ "@webgpu/types": "^0.1.43",
73
+ "typegpu": "0.0.0-alpha.1",
74
+ "@typegpu/wgsl-parser": "0.0.0"
75
+ },
76
+ "packageManager": "pnpm@8.15.8+sha256.691fe176eea9a8a80df20e4976f3dfb44a04841ceb885638fe2a26174f81e65e",
77
+ "peerDependencies": {
78
+ "typed-binary": "^4.0.1"
79
+ },
80
+ "scripts": {
81
+ "dev": "tsup --watch",
82
+ "build": "tsup",
83
+ "test:types": "pnpm tsc --p ./tsconfig.json --noEmit && pnpm tsc --p ./tsconfig.test.json --noEmit"
84
+ }
85
+ }