typegpu 0.1.3 → 0.2.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/chunk-5EPBCOO4.js +8 -0
- package/chunk-5EPBCOO4.js.map +1 -0
- package/chunk-SBJR5ZQJ.cjs +8 -0
- package/chunk-SBJR5ZQJ.cjs.map +1 -0
- package/data/index.cjs +1 -7
- package/data/index.cjs.map +1 -1
- package/data/index.d.cts +476 -43
- package/data/index.d.ts +476 -43
- package/data/index.js +1 -7
- package/data/index.js.map +1 -1
- package/index.cjs +51 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +288 -6
- package/index.d.ts +288 -6
- package/index.js +51 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/{tgpuBuffer-BVk2wCHR.d.cts → types-qmW7FFqN.d.cts} +452 -113
- package/{tgpuBuffer-BVk2wCHR.d.ts → types-qmW7FFqN.d.ts} +452 -113
- package/chunk-2FWG5LPQ.js +0 -2
- package/chunk-2FWG5LPQ.js.map +0 -1
- package/chunk-7EYKOUWH.cjs +0 -2
- package/chunk-7EYKOUWH.cjs.map +0 -1
@@ -1,4 +1,59 @@
|
|
1
|
-
import { Unwrap,
|
1
|
+
import { Unwrap, Parsed, ISchema } from 'typed-binary';
|
2
|
+
|
3
|
+
type Return = {
|
4
|
+
return: Expression | null;
|
5
|
+
};
|
6
|
+
type If = {
|
7
|
+
/** condition */
|
8
|
+
if: Expression;
|
9
|
+
do: Statement;
|
10
|
+
else?: Statement | undefined;
|
11
|
+
};
|
12
|
+
type Block = {
|
13
|
+
block: Statement[];
|
14
|
+
};
|
15
|
+
type Let = {
|
16
|
+
/** variable's identifier */
|
17
|
+
let: string;
|
18
|
+
eq?: Expression | undefined;
|
19
|
+
};
|
20
|
+
type Const = {
|
21
|
+
/** variable's identifier */
|
22
|
+
const: string;
|
23
|
+
eq?: Expression | undefined;
|
24
|
+
};
|
25
|
+
type Statement = Return | If | Block | Let | Const | Expression;
|
26
|
+
type BinaryOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%' | '|' | '^' | '&';
|
27
|
+
type BinaryExpression = {
|
28
|
+
x2: [Expression, BinaryOperator, Expression];
|
29
|
+
};
|
30
|
+
type AssignmentOperator = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '|=' | '^=' | '&=' | '**=' | '||=' | '&&=';
|
31
|
+
type AssignmentExpression = {
|
32
|
+
x2: [Expression, AssignmentOperator, Expression];
|
33
|
+
};
|
34
|
+
type LogicalOperator = '&&' | '||';
|
35
|
+
type LogicalExpression = {
|
36
|
+
x2: [Expression, LogicalOperator, Expression];
|
37
|
+
};
|
38
|
+
type MemberAccess = {
|
39
|
+
'.': [Expression, string];
|
40
|
+
};
|
41
|
+
type IndexAccess = {
|
42
|
+
'[]': [Expression, Expression];
|
43
|
+
};
|
44
|
+
type Call = {
|
45
|
+
/** function identifier */
|
46
|
+
call: Expression;
|
47
|
+
/** expressions passed as function arguments */
|
48
|
+
args: Expression[];
|
49
|
+
};
|
50
|
+
/** A numeric literal */
|
51
|
+
type Num = {
|
52
|
+
num: string;
|
53
|
+
};
|
54
|
+
type Literal = Num | boolean;
|
55
|
+
/** Identifiers are just strings, since string literals are rare in WGSL, and identifiers are everywhere. */
|
56
|
+
type Expression = string | BinaryExpression | AssignmentExpression | LogicalExpression | MemberAccess | IndexAccess | Call | Literal;
|
2
57
|
|
3
58
|
/**
|
4
59
|
* Can be assigned a name. Not to be confused with
|
@@ -9,6 +64,8 @@ interface TgpuNamable {
|
|
9
64
|
}
|
10
65
|
|
11
66
|
type Getter = <T>(plum: TgpuPlum<T>) => T;
|
67
|
+
type Unsubscribe = () => unknown;
|
68
|
+
type ExtractPlumValue<T> = T extends TgpuPlum<infer TValue> ? TValue : never;
|
12
69
|
interface TgpuPlum<TValue = unknown> extends TgpuNamable {
|
13
70
|
readonly __brand: 'TgpuPlum';
|
14
71
|
/**
|
@@ -18,110 +75,68 @@ interface TgpuPlum<TValue = unknown> extends TgpuNamable {
|
|
18
75
|
compute(get: Getter): TValue;
|
19
76
|
}
|
20
77
|
|
21
|
-
interface TgpuBufferUsage<TData extends AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuBindable<TData, TUsage> {
|
22
|
-
value: Unwrap<TData>;
|
23
|
-
}
|
24
|
-
|
25
|
-
type AnyTgpuDataTuple = [AnyTgpuData, ...AnyTgpuData[]] | [];
|
26
|
-
type UnwrapArgs<T extends AnyTgpuDataTuple> = {
|
27
|
-
[Idx in keyof T]: Unwrap<T[Idx]>;
|
28
|
-
};
|
29
|
-
type UnwrapReturn<T extends AnyTgpuData | undefined> = T extends undefined ? void : Unwrap<T>;
|
30
78
|
/**
|
31
|
-
*
|
79
|
+
* Boolean schema representing a single WGSL bool value.
|
80
|
+
* Cannot be used inside buffers as it is not host-shareable.
|
32
81
|
*/
|
33
|
-
|
34
|
-
readonly argTypes: Args;
|
35
|
-
readonly returnType: Return | undefined;
|
36
|
-
/**
|
37
|
-
* Creates a type-safe implementation of this signature
|
38
|
-
*/
|
39
|
-
implement(body: (...args: UnwrapArgs<Args>) => UnwrapReturn<Return>): TgpuFn<Args, Return>;
|
40
|
-
}
|
41
|
-
interface TgpuFnBase<Args extends AnyTgpuDataTuple, Return extends AnyTgpuData | undefined = undefined> extends TgpuResolvable, TgpuNamable {
|
42
|
-
readonly shell: TgpuFnShell<Args, Return>;
|
43
|
-
/** The JS function body passed as an implementation of a TypeGPU function. */
|
44
|
-
readonly body: (...args: UnwrapArgs<Args>) => UnwrapReturn<Return>;
|
45
|
-
readonly bodyResolvable: TgpuResolvable;
|
46
|
-
$uses(dependencyMap: Record<string, unknown>): this;
|
47
|
-
}
|
48
|
-
type TgpuFn<Args extends AnyTgpuDataTuple, Return extends AnyTgpuData | undefined = undefined> = TgpuFnBase<Args, Return> & ((...args: UnwrapArgs<Args>) => UnwrapReturn<Return>);
|
49
|
-
|
50
|
-
type Wgsl = string | number | TgpuResolvable | symbol | boolean;
|
82
|
+
type Bool = TgpuData<boolean>;
|
51
83
|
/**
|
52
|
-
*
|
53
|
-
* and a new resolution ctx is made when going down each level in the tree.
|
84
|
+
* A schema that represents a boolean value. (equivalent to `bool` in WGSL)
|
54
85
|
*/
|
55
|
-
|
56
|
-
addDeclaration(item: TgpuResolvable): void;
|
57
|
-
addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
|
58
|
-
addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
|
59
|
-
addBuiltin(builtin: symbol): void;
|
60
|
-
nameFor(token: TgpuResolvable): string;
|
61
|
-
/**
|
62
|
-
* Unwraps all layers of slot indirection and returns the concrete value if available.
|
63
|
-
* @throws {MissingSlotValueError}
|
64
|
-
*/
|
65
|
-
unwrap<T>(eventual: Eventual<T>): T;
|
66
|
-
resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
|
67
|
-
fnToWgsl(fn: TgpuFn<any, any>, externalMap: Record<string, unknown>): {
|
68
|
-
head: Wgsl;
|
69
|
-
body: Wgsl;
|
70
|
-
};
|
71
|
-
}
|
72
|
-
interface TgpuResolvable {
|
73
|
-
readonly label?: string | undefined;
|
74
|
-
resolve(ctx: ResolutionCtx): string;
|
75
|
-
}
|
76
|
-
interface TgpuIdentifier extends TgpuNamable, TgpuResolvable {
|
77
|
-
}
|
86
|
+
declare const bool: Bool;
|
78
87
|
/**
|
79
|
-
*
|
88
|
+
* Unsigned 32-bit integer schema representing a single WGSL u32 value.
|
80
89
|
*/
|
81
|
-
type
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
90
|
+
type U32 = TgpuData<number> & {
|
91
|
+
kind: 'u32';
|
92
|
+
} & ((v: number | boolean) => number);
|
93
|
+
/**
|
94
|
+
* A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
|
95
|
+
*
|
96
|
+
* Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
|
97
|
+
*
|
98
|
+
* @example
|
99
|
+
* const value = u32(3.14); // 3
|
100
|
+
* @example
|
101
|
+
* const value = u32(-1); // 4294967295
|
102
|
+
* @example
|
103
|
+
* const value = u32(-3.1); // 0
|
104
|
+
*/
|
105
|
+
declare const u32: U32;
|
106
|
+
/**
|
107
|
+
* Signed 32-bit integer schema representing a single WGSL i32 value.
|
108
|
+
*/
|
109
|
+
type I32 = TgpuData<number> & {
|
110
|
+
kind: 'i32';
|
111
|
+
} & ((v: number | boolean) => number);
|
112
|
+
/**
|
113
|
+
* A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
|
114
|
+
*
|
115
|
+
* Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
|
116
|
+
*
|
117
|
+
* @example
|
118
|
+
* const value = i32(3.14); // 3
|
119
|
+
* @example
|
120
|
+
* const value = i32(-3.9); // -3
|
121
|
+
* @example
|
122
|
+
* const value = i32(10000000000) // 1410065408
|
123
|
+
*/
|
124
|
+
declare const i32: I32;
|
125
|
+
/**
|
126
|
+
* 32-bit float schema representing a single WGSL f32 value.
|
127
|
+
*/
|
128
|
+
type F32 = TgpuData<number> & {
|
129
|
+
kind: 'f32';
|
130
|
+
} & ((v: number | boolean) => number);
|
131
|
+
/**
|
132
|
+
* A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
|
133
|
+
*
|
134
|
+
* Can also be called to cast a value to an f32.
|
135
|
+
*
|
136
|
+
* @example
|
137
|
+
* const value = f32(true); // 1
|
138
|
+
*/
|
139
|
+
declare const f32: F32;
|
125
140
|
|
126
141
|
interface Swizzle2<T2, T3, T4> {
|
127
142
|
readonly xx: T2;
|
@@ -428,84 +443,305 @@ interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3, T4> {
|
|
428
443
|
readonly wwwz: T4;
|
429
444
|
readonly wwww: T4;
|
430
445
|
}
|
431
|
-
interface vec2 {
|
446
|
+
interface vec2 extends NumberArrayView {
|
432
447
|
x: number;
|
433
448
|
y: number;
|
434
449
|
[Symbol.iterator](): Iterator<number>;
|
435
450
|
}
|
436
|
-
interface vec3 {
|
451
|
+
interface vec3 extends NumberArrayView {
|
437
452
|
x: number;
|
438
453
|
y: number;
|
439
454
|
z: number;
|
440
455
|
[Symbol.iterator](): Iterator<number>;
|
441
456
|
}
|
442
|
-
interface vec4 {
|
457
|
+
interface vec4 extends NumberArrayView {
|
443
458
|
x: number;
|
444
459
|
y: number;
|
445
460
|
z: number;
|
446
461
|
w: number;
|
447
462
|
[Symbol.iterator](): Iterator<number>;
|
448
463
|
}
|
464
|
+
/**
|
465
|
+
* Type encompassing all available kinds of vector.
|
466
|
+
*/
|
449
467
|
type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
|
468
|
+
/**
|
469
|
+
* Common interface for all vector types, no matter their size and inner type.
|
470
|
+
*/
|
450
471
|
interface vecBase {
|
451
472
|
kind: VecKind;
|
452
473
|
[Symbol.iterator](): Iterator<number>;
|
453
474
|
}
|
454
|
-
|
475
|
+
/**
|
476
|
+
* Type of the `d.vec2f` object/function: vector data type schema/constructor
|
477
|
+
*/
|
478
|
+
type Vec2f = TgpuData<vec2f> & {
|
479
|
+
kind: 'vec2f';
|
480
|
+
} & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
|
481
|
+
/**
|
482
|
+
* Interface representing its WGSL vector type counterpart: vec2f or vec2<f32>.
|
483
|
+
* A vector with 2 elements of type d.f32
|
484
|
+
*/
|
455
485
|
interface vec2f extends vec2, Swizzle2<vec2f, vec3f, vec4f> {
|
456
486
|
/** use to distinguish between vectors of the same size on the type level */
|
457
487
|
kind: 'vec2f';
|
458
488
|
}
|
489
|
+
/**
|
490
|
+
*
|
491
|
+
* Schema representing vec2f - a vector with 2 elements of type f32.
|
492
|
+
* Also a constructor function for this vector value.
|
493
|
+
*
|
494
|
+
* @example
|
495
|
+
* const vector = d.vec2f(); // (0.0, 0.0)
|
496
|
+
* const vector = d.vec2f(1); // (1.0, 1.0)
|
497
|
+
* const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
|
498
|
+
*
|
499
|
+
* @example
|
500
|
+
* const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
|
501
|
+
*/
|
459
502
|
declare const vec2f: Vec2f;
|
460
|
-
|
503
|
+
/**
|
504
|
+
* Type of the `d.vec2i` object/function: vector data type schema/constructor
|
505
|
+
*/
|
506
|
+
type Vec2i = TgpuData<vec2i> & {
|
507
|
+
kind: 'vec2i';
|
508
|
+
} & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
|
509
|
+
/**
|
510
|
+
* Interface representing its WGSL vector type counterpart: vec2i or vec2<i32>.
|
511
|
+
* A vector with 2 elements of type d.i32
|
512
|
+
*/
|
461
513
|
interface vec2i extends vec2, Swizzle2<vec2i, vec3i, vec4i> {
|
462
514
|
/** use to distinguish between vectors of the same size on the type level */
|
463
515
|
kind: 'vec2i';
|
464
516
|
}
|
517
|
+
/**
|
518
|
+
*
|
519
|
+
* Schema representing vec2i - a vector with 2 elements of type i32.
|
520
|
+
* Also a constructor function for this vector value.
|
521
|
+
*
|
522
|
+
* @example
|
523
|
+
* const vector = d.vec2i(); // (0, 0)
|
524
|
+
* const vector = d.vec2i(1); // (1, 1)
|
525
|
+
* const vector = d.vec2i(-1, 1); // (-1, 1)
|
526
|
+
*
|
527
|
+
* @example
|
528
|
+
* const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
|
529
|
+
*/
|
465
530
|
declare const vec2i: Vec2i;
|
466
|
-
|
531
|
+
/**
|
532
|
+
* Type of the `d.vec2u` object/function: vector data type schema/constructor
|
533
|
+
*/
|
534
|
+
type Vec2u = TgpuData<vec2u> & {
|
535
|
+
kind: 'vec2u';
|
536
|
+
} & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
|
537
|
+
/**
|
538
|
+
* Interface representing its WGSL vector type counterpart: vec2u or vec2<u32>.
|
539
|
+
* A vector with 2 elements of type d.u32
|
540
|
+
*/
|
467
541
|
interface vec2u extends vec2, Swizzle2<vec2u, vec3u, vec4u> {
|
468
542
|
/** use to distinguish between vectors of the same size on the type level */
|
469
543
|
kind: 'vec2u';
|
470
544
|
}
|
545
|
+
/**
|
546
|
+
*
|
547
|
+
* Schema representing vec2u - a vector with 2 elements of type u32.
|
548
|
+
* Also a constructor function for this vector value.
|
549
|
+
*
|
550
|
+
* @example
|
551
|
+
* const vector = d.vec2u(); // (0, 0)
|
552
|
+
* const vector = d.vec2u(1); // (1, 1)
|
553
|
+
* const vector = d.vec2u(1, 2); // (1, 2)
|
554
|
+
*
|
555
|
+
* @example
|
556
|
+
* const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
|
557
|
+
*/
|
471
558
|
declare const vec2u: Vec2u;
|
472
|
-
|
559
|
+
/**
|
560
|
+
* Type of the `d.vec3f` object/function: vector data type schema/constructor
|
561
|
+
*/
|
562
|
+
type Vec3f = TgpuData<vec3f> & {
|
563
|
+
kind: 'vec3f';
|
564
|
+
} & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
|
565
|
+
/**
|
566
|
+
* Interface representing its WGSL vector type counterpart: vec3f or vec3<f32>.
|
567
|
+
* A vector with 3 elements of type d.f32
|
568
|
+
*/
|
473
569
|
interface vec3f extends vec3, Swizzle3<vec2f, vec3f, vec4f> {
|
474
570
|
/** use to distinguish between vectors of the same size on the type level */
|
475
571
|
kind: 'vec3f';
|
476
572
|
}
|
573
|
+
/**
|
574
|
+
*
|
575
|
+
* Schema representing vec3f - a vector with 3 elements of type f32.
|
576
|
+
* Also a constructor function for this vector value.
|
577
|
+
*
|
578
|
+
* @example
|
579
|
+
* const vector = d.vec3f(); // (0.0, 0.0, 0.0)
|
580
|
+
* const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
|
581
|
+
* const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
|
582
|
+
*
|
583
|
+
* @example
|
584
|
+
* const buffer = root.createBuffer(d.vec3f, d.vec3f(0, 1, 2)); // buffer holding a d.vec3f value, with an initial value of vec3f(0, 1, 2);
|
585
|
+
*/
|
477
586
|
declare const vec3f: Vec3f;
|
478
|
-
|
587
|
+
/**
|
588
|
+
* Type of the `d.vec3i` object/function: vector data type schema/constructor
|
589
|
+
*/
|
590
|
+
type Vec3i = TgpuData<vec3i> & {
|
591
|
+
kind: 'vec3i';
|
592
|
+
} & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
|
593
|
+
/**
|
594
|
+
* Interface representing its WGSL vector type counterpart: vec3i or vec3<i32>.
|
595
|
+
* A vector with 3 elements of type d.i32
|
596
|
+
*/
|
479
597
|
interface vec3i extends vec3, Swizzle3<vec2i, vec3i, vec4i> {
|
480
598
|
/** use to distinguish between vectors of the same size on the type level */
|
481
599
|
kind: 'vec3i';
|
482
600
|
}
|
601
|
+
/**
|
602
|
+
*
|
603
|
+
* Schema representing vec3i - a vector with 3 elements of type i32.
|
604
|
+
* Also a constructor function for this vector value.
|
605
|
+
*
|
606
|
+
* @example
|
607
|
+
* const vector = d.vec3i(); // (0, 0, 0)
|
608
|
+
* const vector = d.vec3i(1); // (1, 1, 1)
|
609
|
+
* const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
|
610
|
+
*
|
611
|
+
* @example
|
612
|
+
* const buffer = root.createBuffer(d.vec3i, d.vec3i(0, 1, 2)); // buffer holding a d.vec3i value, with an initial value of vec3i(0, 1, 2);
|
613
|
+
*/
|
483
614
|
declare const vec3i: Vec3i;
|
484
|
-
|
615
|
+
/**
|
616
|
+
* Type of the `d.vec3u` object/function: vector data type schema/constructor
|
617
|
+
*/
|
618
|
+
type Vec3u = TgpuData<vec3u> & {
|
619
|
+
kind: 'vec3u';
|
620
|
+
} & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
|
621
|
+
/**
|
622
|
+
* Interface representing its WGSL vector type counterpart: vec3u or vec3<u32>.
|
623
|
+
* A vector with 3 elements of type d.u32
|
624
|
+
*/
|
485
625
|
interface vec3u extends vec3, Swizzle3<vec2u, vec3u, vec4u> {
|
486
626
|
/** use to distinguish between vectors of the same size on the type level */
|
487
627
|
kind: 'vec3u';
|
488
628
|
}
|
629
|
+
/**
|
630
|
+
*
|
631
|
+
* Schema representing vec3u - a vector with 3 elements of type u32.
|
632
|
+
* Also a constructor function for this vector value.
|
633
|
+
*
|
634
|
+
* @example
|
635
|
+
* const vector = d.vec3u(); // (0, 0, 0)
|
636
|
+
* const vector = d.vec3u(1); // (1, 1, 1)
|
637
|
+
* const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
|
638
|
+
*
|
639
|
+
* @example
|
640
|
+
* const buffer = root.createBuffer(d.vec3u, d.vec3u(0, 1, 2)); // buffer holding a d.vec3u value, with an initial value of vec3u(0, 1, 2);
|
641
|
+
*/
|
489
642
|
declare const vec3u: Vec3u;
|
490
|
-
|
643
|
+
/**
|
644
|
+
* Type of the `d.vec4f` object/function: vector data type schema/constructor
|
645
|
+
*/
|
646
|
+
type Vec4f = TgpuData<vec4f> & {
|
647
|
+
kind: 'vec4f';
|
648
|
+
} & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
|
649
|
+
/**
|
650
|
+
* Interface representing its WGSL vector type counterpart: vec4f or vec4<f32>.
|
651
|
+
* A vector with 4 elements of type d.f32
|
652
|
+
*/
|
491
653
|
interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
|
492
654
|
/** use to distinguish between vectors of the same size on the type level */
|
493
655
|
kind: 'vec4f';
|
494
656
|
}
|
657
|
+
/**
|
658
|
+
*
|
659
|
+
* Schema representing vec4f - a vector with 4 elements of type f32.
|
660
|
+
* Also a constructor function for this vector value.
|
661
|
+
*
|
662
|
+
* @example
|
663
|
+
* const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
|
664
|
+
* const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
|
665
|
+
* const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
|
666
|
+
*
|
667
|
+
* @example
|
668
|
+
* const buffer = root.createBuffer(d.vec4f, d.vec4f(0, 1, 2, 3)); // buffer holding a d.vec4f value, with an initial value of vec4f(0, 1, 2, 3);
|
669
|
+
*/
|
495
670
|
declare const vec4f: Vec4f;
|
496
|
-
|
671
|
+
/**
|
672
|
+
* Type of the `d.vec4i` object/function: vector data type schema/constructor
|
673
|
+
*/
|
674
|
+
type Vec4i = TgpuData<vec4i> & {
|
675
|
+
kind: 'vec4i';
|
676
|
+
} & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
|
677
|
+
/**
|
678
|
+
* Interface representing its WGSL vector type counterpart: vec4i or vec4<i32>.
|
679
|
+
* A vector with 4 elements of type d.i32
|
680
|
+
*/
|
497
681
|
interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
|
498
682
|
/** use to distinguish between vectors of the same size on the type level */
|
499
683
|
kind: 'vec4i';
|
500
684
|
}
|
685
|
+
/**
|
686
|
+
*
|
687
|
+
* Schema representing vec4i - a vector with 4 elements of type i32.
|
688
|
+
* Also a constructor function for this vector value.
|
689
|
+
*
|
690
|
+
* @example
|
691
|
+
* const vector = d.vec4i(); // (0, 0, 0, 0)
|
692
|
+
* const vector = d.vec4i(1); // (1, 1, 1, 1)
|
693
|
+
* const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
|
694
|
+
*
|
695
|
+
* @example
|
696
|
+
* const buffer = root.createBuffer(d.vec4i, d.vec4i(0, 1, 2, 3)); // buffer holding a d.vec4i value, with an initial value of vec4i(0, 1, 2, 3);
|
697
|
+
*/
|
501
698
|
declare const vec4i: Vec4i;
|
502
|
-
|
699
|
+
/**
|
700
|
+
* Type of the `d.vec4u` object/function: vector data type schema/constructor
|
701
|
+
*/
|
702
|
+
type Vec4u = TgpuData<vec4u> & {
|
703
|
+
kind: 'vec4u';
|
704
|
+
} & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
|
705
|
+
/**
|
706
|
+
* Interface representing its WGSL vector type counterpart: vec4u or vec4<u32>.
|
707
|
+
* A vector with 4 elements of type d.u32
|
708
|
+
*/
|
503
709
|
interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
|
504
710
|
/** use to distinguish between vectors of the same size on the type level */
|
505
711
|
kind: 'vec4u';
|
506
712
|
}
|
713
|
+
/**
|
714
|
+
*
|
715
|
+
* Schema representing vec4u - a vector with 4 elements of type u32.
|
716
|
+
* Also a constructor function for this vector value.
|
717
|
+
*
|
718
|
+
* @example
|
719
|
+
* const vector = d.vec4u(); // (0, 0, 0, 0)
|
720
|
+
* const vector = d.vec4u(1); // (1, 1, 1, 1)
|
721
|
+
* const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
|
722
|
+
*
|
723
|
+
* @example
|
724
|
+
* const buffer = root.createBuffer(d.vec4u, d.vec4u(0, 1, 2, 3)); // buffer holding a d.vec4u value, with an initial value of vec4u(0, 1, 2, 3);
|
725
|
+
*/
|
507
726
|
declare const vec4u: Vec4u;
|
508
727
|
|
728
|
+
interface TgpuBufferUniform<TData extends AnyTgpuData> extends TgpuBindable<TData, 'uniform'> {
|
729
|
+
readonly resourceType: 'buffer-usage';
|
730
|
+
readonly value: Unwrap<TData>;
|
731
|
+
}
|
732
|
+
interface TgpuBufferReadonly<TData extends AnyTgpuData> extends TgpuBindable<TData, 'readonly'> {
|
733
|
+
readonly resourceType: 'buffer-usage';
|
734
|
+
readonly value: Unwrap<TData>;
|
735
|
+
}
|
736
|
+
interface TgpuBufferMutable<TData extends AnyTgpuData> extends TgpuBindable<TData, 'mutable'> {
|
737
|
+
readonly resourceType: 'buffer-usage';
|
738
|
+
value: Unwrap<TData>;
|
739
|
+
}
|
740
|
+
interface TgpuBufferUsage<TData extends AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuBindable<TData, TUsage> {
|
741
|
+
readonly resourceType: 'buffer-usage';
|
742
|
+
value: Unwrap<TData>;
|
743
|
+
}
|
744
|
+
|
509
745
|
interface Uniform {
|
510
746
|
usableAsUniform: true;
|
511
747
|
}
|
@@ -519,6 +755,7 @@ interface Vertex {
|
|
519
755
|
}
|
520
756
|
declare const Vertex: Vertex;
|
521
757
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
758
|
+
type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? Uniform : T extends 'storage' ? Storage : T extends 'vertex' ? Vertex : never;
|
522
759
|
interface TgpuBuffer<TData extends AnyTgpuData> extends TgpuNamable {
|
523
760
|
readonly resourceType: 'buffer';
|
524
761
|
readonly dataType: TData;
|
@@ -527,7 +764,7 @@ interface TgpuBuffer<TData extends AnyTgpuData> extends TgpuNamable {
|
|
527
764
|
readonly buffer: GPUBuffer;
|
528
765
|
readonly device: GPUDevice;
|
529
766
|
readonly destroyed: boolean;
|
530
|
-
$usage<T extends (
|
767
|
+
$usage<T extends ('uniform' | 'storage' | 'vertex')[]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
|
531
768
|
$addFlags(flags: GPUBufferUsageFlags): this;
|
532
769
|
$device(device: GPUDevice): this;
|
533
770
|
write(data: Parsed<TData> | TgpuBuffer<TData>): void;
|
@@ -538,4 +775,106 @@ declare function isUsableAsUniform<T extends TgpuBuffer<AnyTgpuData>>(buffer: T)
|
|
538
775
|
declare function isUsableAsStorage<T extends TgpuBuffer<AnyTgpuData>>(buffer: T): buffer is T & Storage;
|
539
776
|
declare function isUsableAsVertex<T extends TgpuBuffer<AnyTgpuData>>(buffer: T): buffer is T & Vertex;
|
540
777
|
|
541
|
-
|
778
|
+
interface TgpuFnShellBase<Args extends AnyTgpuData[], Return extends AnyTgpuData | undefined> {
|
779
|
+
readonly argTypes: Args;
|
780
|
+
readonly returnType: Return | undefined;
|
781
|
+
}
|
782
|
+
|
783
|
+
type Wgsl = string | number | TgpuResolvable | symbol | boolean;
|
784
|
+
type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
|
785
|
+
interface NumberArrayView {
|
786
|
+
readonly length: number;
|
787
|
+
[n: number]: number;
|
788
|
+
}
|
789
|
+
/**
|
790
|
+
* Removes properties from record type that extend `Prop`
|
791
|
+
*/
|
792
|
+
type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
|
793
|
+
[Key in keyof T]: T[Key] extends Prop ? never : Key;
|
794
|
+
}[keyof T]>;
|
795
|
+
/**
|
796
|
+
* Passed into each resolvable item. All sibling items share a resolution ctx,
|
797
|
+
* and a new resolution ctx is made when going down each level in the tree.
|
798
|
+
*/
|
799
|
+
interface ResolutionCtx {
|
800
|
+
addDeclaration(item: TgpuResolvable): void;
|
801
|
+
addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
|
802
|
+
addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
|
803
|
+
addBuiltin(builtin: symbol): void;
|
804
|
+
nameFor(token: TgpuResolvable): string;
|
805
|
+
/**
|
806
|
+
* Unwraps all layers of slot indirection and returns the concrete value if available.
|
807
|
+
* @throws {MissingSlotValueError}
|
808
|
+
*/
|
809
|
+
unwrap<T>(eventual: Eventual<T>): T;
|
810
|
+
resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
|
811
|
+
transpileFn(fn: string): {
|
812
|
+
argNames: string[];
|
813
|
+
body: Block;
|
814
|
+
externalNames: string[];
|
815
|
+
};
|
816
|
+
fnToWgsl(shell: TgpuFnShellBase<any, AnyTgpuData | undefined>, argNames: string[], body: Block, externalMap: Record<string, unknown>): {
|
817
|
+
head: Wgsl;
|
818
|
+
body: Wgsl;
|
819
|
+
};
|
820
|
+
}
|
821
|
+
interface TgpuResolvable {
|
822
|
+
readonly label?: string | undefined;
|
823
|
+
resolve(ctx: ResolutionCtx): string;
|
824
|
+
}
|
825
|
+
interface TgpuIdentifier extends TgpuNamable, TgpuResolvable {
|
826
|
+
}
|
827
|
+
/**
|
828
|
+
* Represents a value that is available at resolution time.
|
829
|
+
*/
|
830
|
+
type Eventual<T> = T | TgpuSlot<T>;
|
831
|
+
type SlotValuePair<T> = [TgpuSlot<T>, T];
|
832
|
+
interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
|
833
|
+
readonly allocatable: TgpuBuffer<TData>;
|
834
|
+
readonly usage: TUsage;
|
835
|
+
}
|
836
|
+
type TgpuSamplerType = 'sampler' | 'sampler_comparison';
|
837
|
+
type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
|
838
|
+
type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
|
839
|
+
type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
|
840
|
+
type TgpuExternalTextureType = 'texture_external';
|
841
|
+
type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
|
842
|
+
interface TgpuRenderResource extends TgpuResolvable {
|
843
|
+
readonly type: TgpuRenderResourceType;
|
844
|
+
}
|
845
|
+
type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
|
846
|
+
type ValueOf<T> = T extends TgpuSlot<infer I> ? ValueOf<I> : T extends TgpuBufferUsage<infer D> ? ValueOf<D> : T extends TgpuData<unknown> ? Unwrap<T> : T;
|
847
|
+
interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
|
848
|
+
readonly isLoose: false;
|
849
|
+
readonly byteAlignment: number;
|
850
|
+
readonly size: number;
|
851
|
+
}
|
852
|
+
interface TgpuLooseData<TInner> extends ISchema<TInner> {
|
853
|
+
readonly isLoose: true;
|
854
|
+
readonly byteAlignment: number;
|
855
|
+
readonly size: number;
|
856
|
+
}
|
857
|
+
type AnyTgpuData = TgpuData<unknown>;
|
858
|
+
type AnyTgpuLooseData = TgpuLooseData<unknown>;
|
859
|
+
interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
|
860
|
+
readonly scope: TScope;
|
861
|
+
readonly pointsTo: TInner;
|
862
|
+
}
|
863
|
+
interface BoundTgpuCode extends TgpuResolvable {
|
864
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): BoundTgpuCode;
|
865
|
+
}
|
866
|
+
interface TgpuCode extends BoundTgpuCode, TgpuNamable {
|
867
|
+
}
|
868
|
+
interface TgpuSlot<T> extends TgpuNamable {
|
869
|
+
readonly __brand: 'TgpuSlot';
|
870
|
+
readonly defaultValue: T | undefined;
|
871
|
+
readonly label?: string | undefined;
|
872
|
+
/**
|
873
|
+
* Used to determine if code generated using either value `a` or `b` in place
|
874
|
+
* of the slot will be equivalent. Defaults to `Object.is`.
|
875
|
+
*/
|
876
|
+
areEqual(a: T, b: T): boolean;
|
877
|
+
value: ValueOf<T>;
|
878
|
+
}
|
879
|
+
|
880
|
+
export { vec2u as $, type AnyTgpuData as A, type BoundTgpuCode as B, vec4f as C, type Vec2u as D, type ExtractPlumValue as E, type F32 as F, type Vec2i as G, type Vec2f as H, type I32 as I, type Vec3f as J, type Vec3u as K, type Vec3i as L, type TgpuPointer as M, type NumberArrayView as N, type OmitProps as O, type Bool as P, bool as Q, type ResolutionCtx as R, Storage as S, type TgpuRenderResource as T, Uniform as U, type Vec4u as V, u32 as W, i32 as X, f32 as Y, type VecKind as Z, vec2i as _, type TgpuNamable as a, vec4i as a0, vec4u as a1, type TgpuBuffer as b, type TgpuBufferUsage as c, type TgpuBufferUniform as d, type TgpuShaderStage as e, type TgpuBufferReadonly as f, type TgpuBufferMutable as g, type U32 as h, type Vec4i as i, type Vec4f as j, type TgpuPlum as k, type Unsubscribe as l, type TgpuCode as m, type Block as n, vec3f as o, vec3i as p, vec3u as q, type TgpuData as r, isUsableAsStorage as s, isUsableAsUniform as t, isUsableAsVertex as u, type vecBase as v, Vertex as w, type AnyTgpuLooseData as x, type TgpuLooseData as y, vec2f as z };
|