@daneren2005/shared-memory-objects 0.0.20 → 1.0.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.
- package/README.md +167 -167
- package/dist/shared-memory-objects.js +480 -576
- package/dist/shared-memory-objects.js.map +1 -1
- package/dist/shared-memory-objects.umd.cjs +1 -1
- package/dist/shared-memory-objects.umd.cjs.map +1 -1
- package/dist/src/memory-heap.d.ts +0 -1
- package/dist/src/utils/atomic-math.d.ts +4 -4
- package/dist/src/utils/typedarray.d.ts +278 -278
- package/package.json +70 -72
|
@@ -15,7 +15,6 @@ export default class MemoryHeap {
|
|
|
15
15
|
getSharedAlloc(shared: SharedAllocatedMemory): AllocatedMemory | undefined;
|
|
16
16
|
get currentUsed(): number;
|
|
17
17
|
get totalAllocated(): number;
|
|
18
|
-
prettyMemory(): string;
|
|
19
18
|
getSharedMemory(): MemoryHeapMemory;
|
|
20
19
|
}
|
|
21
20
|
type OnGrowBuffer = (newBuffer: GrowBufferData) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function addAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, max: number):
|
|
2
|
-
export declare function subtractAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, min: number):
|
|
3
|
-
export declare function addAtomicFloat32(array: Float32Array, index: number, amount: number, max: number):
|
|
4
|
-
export declare function subtractAtomicFloat(array: Float32Array, index: number, amount: number, min: number):
|
|
1
|
+
export declare function addAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, max: number): number;
|
|
2
|
+
export declare function subtractAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, min: number): number;
|
|
3
|
+
export declare function addAtomicFloat32(array: Float32Array, index: number, amount: number, max: number): number;
|
|
4
|
+
export declare function subtractAtomicFloat(array: Float32Array, index: number, amount: number, min: number): number;
|
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
export type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
|
|
2
|
-
export type NumericArray = number[] | TypedArray;
|
|
3
|
-
export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
|
|
4
|
-
export type BigTypedArray = BigInt64Array | BigUint64Array;
|
|
5
|
-
export type FloatArray = Float32Array | Float64Array;
|
|
6
|
-
export type IntArray = Int8Array | Int16Array | Int32Array;
|
|
7
|
-
export type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
|
|
8
|
-
export type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
|
|
9
|
-
export type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
|
|
10
|
-
export type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
|
|
11
|
-
export type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
|
|
12
|
-
export type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
|
|
13
|
-
/**
|
|
14
|
-
* Type IDs for typed array backed buffers and generally describing binary data
|
|
15
|
-
* values.
|
|
16
|
-
*
|
|
17
|
-
* {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
|
|
18
|
-
*/
|
|
19
|
-
export type Type = 'u8' | 'u8c' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f32' | 'f64';
|
|
20
|
-
export type BigType = 'i64' | 'u64';
|
|
21
|
-
export type UintType = 'u8' | 'u8c' | 'u16' | 'u32';
|
|
22
|
-
export type IntType = 'i8' | 'i16' | 'i32';
|
|
23
|
-
export type FloatType = 'f32' | 'f64';
|
|
24
|
-
/**
|
|
25
|
-
* WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
|
|
26
|
-
*
|
|
27
|
-
* {@link Type}
|
|
28
|
-
* {@link GL2TYPE}
|
|
29
|
-
* {@link TYPE2GL}
|
|
30
|
-
*/
|
|
31
|
-
export declare enum GLType {
|
|
32
|
-
I8 = 5120,
|
|
33
|
-
U8 = 5121,
|
|
34
|
-
I16 = 5122,
|
|
35
|
-
U16 = 5123,
|
|
36
|
-
I32 = 5124,
|
|
37
|
-
U32 = 5125,
|
|
38
|
-
F32 = 5126
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Conversion from {@link GLType} to {@link Type} enums.
|
|
42
|
-
*/
|
|
43
|
-
export declare const GL2TYPE: Record<GLType, Type>;
|
|
44
|
-
/**
|
|
45
|
-
* Potentially lossy conversion from {@link Type} to {@link GLType} enums.
|
|
46
|
-
*
|
|
47
|
-
* Not all enums are mappable:
|
|
48
|
-
*
|
|
49
|
-
* - `F64` maps to `undefined`, since unsupported by WebGL
|
|
50
|
-
* - `U8C` maps to "u8"
|
|
51
|
-
*/
|
|
52
|
-
export declare const TYPE2GL: Record<Type, GLType | undefined>;
|
|
53
|
-
/**
|
|
54
|
-
* Size information (in bytes) for {@link Type} and {@link BigType}. Also see
|
|
55
|
-
* {@link sizeOf}.
|
|
56
|
-
*/
|
|
57
|
-
export declare const SIZEOF: {
|
|
58
|
-
u8: number;
|
|
59
|
-
u8c: number;
|
|
60
|
-
i8: number;
|
|
61
|
-
u16: number;
|
|
62
|
-
i16: number;
|
|
63
|
-
u32: number;
|
|
64
|
-
i32: number;
|
|
65
|
-
i64: number;
|
|
66
|
-
u64: number;
|
|
67
|
-
f32: number;
|
|
68
|
-
f64: number;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Bit shift values to convert byte addresses into array indices for all
|
|
72
|
-
* {@link Type}s and {@link BigType}s.
|
|
73
|
-
*/
|
|
74
|
-
export declare const BIT_SHIFTS: {
|
|
75
|
-
i8: number;
|
|
76
|
-
u8: number;
|
|
77
|
-
u8c: number;
|
|
78
|
-
i16: number;
|
|
79
|
-
u16: number;
|
|
80
|
-
i32: number;
|
|
81
|
-
u32: number;
|
|
82
|
-
i64: number;
|
|
83
|
-
u64: number;
|
|
84
|
-
f32: number;
|
|
85
|
-
f64: number;
|
|
86
|
-
};
|
|
87
|
-
export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
|
|
88
|
-
export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
|
|
89
|
-
export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
|
|
90
|
-
export declare const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
|
|
91
|
-
export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
|
|
92
|
-
export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
|
|
93
|
-
u8: Uint8Array;
|
|
94
|
-
u8c: Uint8ClampedArray;
|
|
95
|
-
i8: Int8Array;
|
|
96
|
-
u16: Uint16Array;
|
|
97
|
-
i16: Int16Array;
|
|
98
|
-
u32: Uint32Array;
|
|
99
|
-
i32: Int32Array;
|
|
100
|
-
f32: Float32Array;
|
|
101
|
-
f64: Float64Array;
|
|
102
|
-
[GLType.U8]: Uint8Array;
|
|
103
|
-
[GLType.I8]: Int8Array;
|
|
104
|
-
[GLType.U16]: Uint16Array;
|
|
105
|
-
[GLType.I16]: Int16Array;
|
|
106
|
-
[GLType.U32]: Uint32Array;
|
|
107
|
-
[GLType.I32]: Int32Array;
|
|
108
|
-
[GLType.F32]: Float32Array;
|
|
109
|
-
}
|
|
110
|
-
export interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {
|
|
111
|
-
i64: BigInt64Array;
|
|
112
|
-
u64: BigUint64Array;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Returns canonical {@link Type} value of `type` by first
|
|
116
|
-
* attempting to resolve it as {@link GLType} enum.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* asNativeType(GLType.F32) => "f32"
|
|
121
|
-
* asNativeType("f32") => "f32"
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @param type -
|
|
125
|
-
*/
|
|
126
|
-
export declare const asNativeType: (type: GLType | Type) => Type;
|
|
127
|
-
/**
|
|
128
|
-
* Returns suitable {@link GLType} enum of `type`.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* asGLType("f32") => GLType.F32
|
|
133
|
-
* asGLType(GLType.F32) => GLType.F32
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* @param type -
|
|
137
|
-
*/
|
|
138
|
-
export declare const asGLType: (type: GLType | Type) => GLType;
|
|
139
|
-
/**
|
|
140
|
-
* Coerces given numeric args to integer values.
|
|
141
|
-
*/
|
|
142
|
-
export declare const asInt: (...args: number[]) => number[];
|
|
143
|
-
/**
|
|
144
|
-
* Returns byte size for given {@link Type} ID or {@link GLType} enum.
|
|
145
|
-
*
|
|
146
|
-
* @param type -
|
|
147
|
-
*/
|
|
148
|
-
export declare const sizeOf: (type: Type | BigType | GLType) => number;
|
|
149
|
-
/**
|
|
150
|
-
* Constructs new typed array of given {@link Type}, {@link GLType} or
|
|
151
|
-
* {@link BigType}. Supports all arities of standard typed array ctors.
|
|
152
|
-
*
|
|
153
|
-
* @param type - array type enum
|
|
154
|
-
*/
|
|
155
|
-
export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
|
|
156
|
-
export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
|
|
157
|
-
export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
|
|
158
|
-
export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
|
|
159
|
-
export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
|
|
160
|
-
export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
|
|
161
|
-
/**
|
|
162
|
-
* Constructs a typed array for given `type` and populates it with given vector
|
|
163
|
-
* values.
|
|
164
|
-
*
|
|
165
|
-
* @remarks
|
|
166
|
-
* The size of the array will be `data.length * stride`, where `stride` is the
|
|
167
|
-
* number of elements per item and defaulting to the size of the first data
|
|
168
|
-
* item/vector given.
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```ts
|
|
172
|
-
* // inferred stride=2 (2d vectors)
|
|
173
|
-
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
|
|
174
|
-
* // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
|
|
175
|
-
*
|
|
176
|
-
* // with custom stride=4
|
|
177
|
-
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
|
|
178
|
-
* // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* @param type
|
|
182
|
-
* @param data
|
|
183
|
-
* @param stride
|
|
184
|
-
*/
|
|
185
|
-
export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
|
|
186
|
-
export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
|
|
187
|
-
/**
|
|
188
|
-
* Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
|
|
189
|
-
* Standard JS arrays will default to {@link "f64"}.
|
|
190
|
-
*
|
|
191
|
-
* @param x -
|
|
192
|
-
*/
|
|
193
|
-
export declare const typedArrayType: (x: NumericArray) => Type;
|
|
194
|
-
/**
|
|
195
|
-
* Returns the smallest possible *unsigned* int type enum for given `x`.
|
|
196
|
-
* E.g. if `x <= 256`, the function returns `"u8"`.
|
|
197
|
-
*
|
|
198
|
-
* @param x - value to classify
|
|
199
|
-
*/
|
|
200
|
-
export declare const uintTypeForSize: (x: number) => UintType;
|
|
201
|
-
/**
|
|
202
|
-
* Returns the smallest possible *signed* int type enum for given `x`.
|
|
203
|
-
* E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
|
|
204
|
-
*
|
|
205
|
-
* @param x - value to classify
|
|
206
|
-
*/
|
|
207
|
-
export declare const intTypeForSize: (x: number) => IntType;
|
|
208
|
-
/**
|
|
209
|
-
* Returns suitable {@link UintType} for given bit size (`[0,32]` range)
|
|
210
|
-
*
|
|
211
|
-
* @param x -
|
|
212
|
-
*/
|
|
213
|
-
export declare const uintTypeForBits: (x: number) => UintType;
|
|
214
|
-
/**
|
|
215
|
-
* Returns suitable {@link IntType} for given bit size (`[0,32]` range)
|
|
216
|
-
*
|
|
217
|
-
* @param x -
|
|
218
|
-
*/
|
|
219
|
-
export declare const intTypeForBits: (x: number) => IntType;
|
|
220
|
-
/**
|
|
221
|
-
* Returns the next smaller {@link IntType} for given type (or the same type if
|
|
222
|
-
* already the narrowest).
|
|
223
|
-
*
|
|
224
|
-
* @param t
|
|
225
|
-
*/
|
|
226
|
-
export declare const narrowInt: (t: IntType | 'i64') => 'i8' | 'i16' | 'i32';
|
|
227
|
-
/**
|
|
228
|
-
* Returns the next larger {@link IntType} for given type (or the same type if
|
|
229
|
-
* already the widest).
|
|
230
|
-
*
|
|
231
|
-
* @param t
|
|
232
|
-
*/
|
|
233
|
-
export declare const widenInt: (t: IntType) => 'i16' | 'i32' | 'i64';
|
|
234
|
-
/**
|
|
235
|
-
* Returns the next smaller {@link UintType} for given type (or the same type if
|
|
236
|
-
* already the narrowest).
|
|
237
|
-
*
|
|
238
|
-
* @remarks
|
|
239
|
-
* If type is `u8c`, returns `u8`.
|
|
240
|
-
*
|
|
241
|
-
* @param t
|
|
242
|
-
*/
|
|
243
|
-
export declare const narrowUint: (t: UintType | 'u64') => 'u8' | 'u16' | 'u32';
|
|
244
|
-
/**
|
|
245
|
-
* Returns the next larger {@link UintType} for given type (or the same type if
|
|
246
|
-
* already the widest).
|
|
247
|
-
*
|
|
248
|
-
* @param t
|
|
249
|
-
*/
|
|
250
|
-
export declare const widenUint: (t: UintType) => 'u16' | 'u32' | 'u64';
|
|
251
|
-
/**
|
|
252
|
-
* Returns the next smaller {@link FloatType} for given type (or the same type
|
|
253
|
-
* if already the narrowest).
|
|
254
|
-
*
|
|
255
|
-
* @param t
|
|
256
|
-
*/
|
|
257
|
-
export declare const narrowFloat: (t: FloatType) => string;
|
|
258
|
-
/**
|
|
259
|
-
* Returns the next larger {@link FloatType} for given type (or the same type if
|
|
260
|
-
* already the widest).
|
|
261
|
-
*
|
|
262
|
-
* @param t
|
|
263
|
-
*/
|
|
264
|
-
export declare const widenFloat: (t: FloatType) => string;
|
|
265
|
-
/**
|
|
266
|
-
* Returns the next smaller type (i.e. {@link IntType}, {@link UintType} or
|
|
267
|
-
* {@link FloatType}) for given type (or the same type if already the smallest).
|
|
268
|
-
*
|
|
269
|
-
* @param t
|
|
270
|
-
*/
|
|
271
|
-
export declare const narrowType: (t: Type | BigType) => string;
|
|
272
|
-
/**
|
|
273
|
-
* Returns the next larger type (i.e. {@link IntType}, {@link UintType} or
|
|
274
|
-
* {@link FloatType}) for given type (or the same type if already the widest).
|
|
275
|
-
*
|
|
276
|
-
* @param t
|
|
277
|
-
*/
|
|
278
|
-
export declare const widenType: (t: Type | BigType) => string;
|
|
1
|
+
export type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
|
|
2
|
+
export type NumericArray = number[] | TypedArray;
|
|
3
|
+
export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
|
|
4
|
+
export type BigTypedArray = BigInt64Array | BigUint64Array;
|
|
5
|
+
export type FloatArray = Float32Array | Float64Array;
|
|
6
|
+
export type IntArray = Int8Array | Int16Array | Int32Array;
|
|
7
|
+
export type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
|
|
8
|
+
export type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
|
|
9
|
+
export type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
|
|
10
|
+
export type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
|
|
11
|
+
export type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
|
|
12
|
+
export type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
|
|
13
|
+
/**
|
|
14
|
+
* Type IDs for typed array backed buffers and generally describing binary data
|
|
15
|
+
* values.
|
|
16
|
+
*
|
|
17
|
+
* {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
|
|
18
|
+
*/
|
|
19
|
+
export type Type = 'u8' | 'u8c' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f32' | 'f64';
|
|
20
|
+
export type BigType = 'i64' | 'u64';
|
|
21
|
+
export type UintType = 'u8' | 'u8c' | 'u16' | 'u32';
|
|
22
|
+
export type IntType = 'i8' | 'i16' | 'i32';
|
|
23
|
+
export type FloatType = 'f32' | 'f64';
|
|
24
|
+
/**
|
|
25
|
+
* WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
|
|
26
|
+
*
|
|
27
|
+
* {@link Type}
|
|
28
|
+
* {@link GL2TYPE}
|
|
29
|
+
* {@link TYPE2GL}
|
|
30
|
+
*/
|
|
31
|
+
export declare enum GLType {
|
|
32
|
+
I8 = 5120,
|
|
33
|
+
U8 = 5121,
|
|
34
|
+
I16 = 5122,
|
|
35
|
+
U16 = 5123,
|
|
36
|
+
I32 = 5124,
|
|
37
|
+
U32 = 5125,
|
|
38
|
+
F32 = 5126
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Conversion from {@link GLType} to {@link Type} enums.
|
|
42
|
+
*/
|
|
43
|
+
export declare const GL2TYPE: Record<GLType, Type>;
|
|
44
|
+
/**
|
|
45
|
+
* Potentially lossy conversion from {@link Type} to {@link GLType} enums.
|
|
46
|
+
*
|
|
47
|
+
* Not all enums are mappable:
|
|
48
|
+
*
|
|
49
|
+
* - `F64` maps to `undefined`, since unsupported by WebGL
|
|
50
|
+
* - `U8C` maps to "u8"
|
|
51
|
+
*/
|
|
52
|
+
export declare const TYPE2GL: Record<Type, GLType | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Size information (in bytes) for {@link Type} and {@link BigType}. Also see
|
|
55
|
+
* {@link sizeOf}.
|
|
56
|
+
*/
|
|
57
|
+
export declare const SIZEOF: {
|
|
58
|
+
u8: number;
|
|
59
|
+
u8c: number;
|
|
60
|
+
i8: number;
|
|
61
|
+
u16: number;
|
|
62
|
+
i16: number;
|
|
63
|
+
u32: number;
|
|
64
|
+
i32: number;
|
|
65
|
+
i64: number;
|
|
66
|
+
u64: number;
|
|
67
|
+
f32: number;
|
|
68
|
+
f64: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Bit shift values to convert byte addresses into array indices for all
|
|
72
|
+
* {@link Type}s and {@link BigType}s.
|
|
73
|
+
*/
|
|
74
|
+
export declare const BIT_SHIFTS: {
|
|
75
|
+
i8: number;
|
|
76
|
+
u8: number;
|
|
77
|
+
u8c: number;
|
|
78
|
+
i16: number;
|
|
79
|
+
u16: number;
|
|
80
|
+
i32: number;
|
|
81
|
+
u32: number;
|
|
82
|
+
i64: number;
|
|
83
|
+
u64: number;
|
|
84
|
+
f32: number;
|
|
85
|
+
f64: number;
|
|
86
|
+
};
|
|
87
|
+
export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
|
|
88
|
+
export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
|
|
89
|
+
export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
|
|
90
|
+
export declare const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
|
|
91
|
+
export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
|
|
92
|
+
export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
|
|
93
|
+
u8: Uint8Array;
|
|
94
|
+
u8c: Uint8ClampedArray;
|
|
95
|
+
i8: Int8Array;
|
|
96
|
+
u16: Uint16Array;
|
|
97
|
+
i16: Int16Array;
|
|
98
|
+
u32: Uint32Array;
|
|
99
|
+
i32: Int32Array;
|
|
100
|
+
f32: Float32Array;
|
|
101
|
+
f64: Float64Array;
|
|
102
|
+
[GLType.U8]: Uint8Array;
|
|
103
|
+
[GLType.I8]: Int8Array;
|
|
104
|
+
[GLType.U16]: Uint16Array;
|
|
105
|
+
[GLType.I16]: Int16Array;
|
|
106
|
+
[GLType.U32]: Uint32Array;
|
|
107
|
+
[GLType.I32]: Int32Array;
|
|
108
|
+
[GLType.F32]: Float32Array;
|
|
109
|
+
}
|
|
110
|
+
export interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {
|
|
111
|
+
i64: BigInt64Array;
|
|
112
|
+
u64: BigUint64Array;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns canonical {@link Type} value of `type` by first
|
|
116
|
+
* attempting to resolve it as {@link GLType} enum.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* asNativeType(GLType.F32) => "f32"
|
|
121
|
+
* asNativeType("f32") => "f32"
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param type -
|
|
125
|
+
*/
|
|
126
|
+
export declare const asNativeType: (type: GLType | Type) => Type;
|
|
127
|
+
/**
|
|
128
|
+
* Returns suitable {@link GLType} enum of `type`.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* asGLType("f32") => GLType.F32
|
|
133
|
+
* asGLType(GLType.F32) => GLType.F32
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @param type -
|
|
137
|
+
*/
|
|
138
|
+
export declare const asGLType: (type: GLType | Type) => GLType;
|
|
139
|
+
/**
|
|
140
|
+
* Coerces given numeric args to integer values.
|
|
141
|
+
*/
|
|
142
|
+
export declare const asInt: (...args: number[]) => number[];
|
|
143
|
+
/**
|
|
144
|
+
* Returns byte size for given {@link Type} ID or {@link GLType} enum.
|
|
145
|
+
*
|
|
146
|
+
* @param type -
|
|
147
|
+
*/
|
|
148
|
+
export declare const sizeOf: (type: Type | BigType | GLType) => number;
|
|
149
|
+
/**
|
|
150
|
+
* Constructs new typed array of given {@link Type}, {@link GLType} or
|
|
151
|
+
* {@link BigType}. Supports all arities of standard typed array ctors.
|
|
152
|
+
*
|
|
153
|
+
* @param type - array type enum
|
|
154
|
+
*/
|
|
155
|
+
export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
|
|
156
|
+
export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
|
|
157
|
+
export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
|
|
158
|
+
export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
|
|
159
|
+
export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
|
|
160
|
+
export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
|
|
161
|
+
/**
|
|
162
|
+
* Constructs a typed array for given `type` and populates it with given vector
|
|
163
|
+
* values.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* The size of the array will be `data.length * stride`, where `stride` is the
|
|
167
|
+
* number of elements per item and defaulting to the size of the first data
|
|
168
|
+
* item/vector given.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* // inferred stride=2 (2d vectors)
|
|
173
|
+
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
|
|
174
|
+
* // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
|
|
175
|
+
*
|
|
176
|
+
* // with custom stride=4
|
|
177
|
+
* typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
|
|
178
|
+
* // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param type
|
|
182
|
+
* @param data
|
|
183
|
+
* @param stride
|
|
184
|
+
*/
|
|
185
|
+
export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
|
|
186
|
+
export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
|
|
187
|
+
/**
|
|
188
|
+
* Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
|
|
189
|
+
* Standard JS arrays will default to {@link "f64"}.
|
|
190
|
+
*
|
|
191
|
+
* @param x -
|
|
192
|
+
*/
|
|
193
|
+
export declare const typedArrayType: (x: NumericArray) => Type;
|
|
194
|
+
/**
|
|
195
|
+
* Returns the smallest possible *unsigned* int type enum for given `x`.
|
|
196
|
+
* E.g. if `x <= 256`, the function returns `"u8"`.
|
|
197
|
+
*
|
|
198
|
+
* @param x - value to classify
|
|
199
|
+
*/
|
|
200
|
+
export declare const uintTypeForSize: (x: number) => UintType;
|
|
201
|
+
/**
|
|
202
|
+
* Returns the smallest possible *signed* int type enum for given `x`.
|
|
203
|
+
* E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
|
|
204
|
+
*
|
|
205
|
+
* @param x - value to classify
|
|
206
|
+
*/
|
|
207
|
+
export declare const intTypeForSize: (x: number) => IntType;
|
|
208
|
+
/**
|
|
209
|
+
* Returns suitable {@link UintType} for given bit size (`[0,32]` range)
|
|
210
|
+
*
|
|
211
|
+
* @param x -
|
|
212
|
+
*/
|
|
213
|
+
export declare const uintTypeForBits: (x: number) => UintType;
|
|
214
|
+
/**
|
|
215
|
+
* Returns suitable {@link IntType} for given bit size (`[0,32]` range)
|
|
216
|
+
*
|
|
217
|
+
* @param x -
|
|
218
|
+
*/
|
|
219
|
+
export declare const intTypeForBits: (x: number) => IntType;
|
|
220
|
+
/**
|
|
221
|
+
* Returns the next smaller {@link IntType} for given type (or the same type if
|
|
222
|
+
* already the narrowest).
|
|
223
|
+
*
|
|
224
|
+
* @param t
|
|
225
|
+
*/
|
|
226
|
+
export declare const narrowInt: (t: IntType | 'i64') => 'i8' | 'i16' | 'i32';
|
|
227
|
+
/**
|
|
228
|
+
* Returns the next larger {@link IntType} for given type (or the same type if
|
|
229
|
+
* already the widest).
|
|
230
|
+
*
|
|
231
|
+
* @param t
|
|
232
|
+
*/
|
|
233
|
+
export declare const widenInt: (t: IntType) => 'i16' | 'i32' | 'i64';
|
|
234
|
+
/**
|
|
235
|
+
* Returns the next smaller {@link UintType} for given type (or the same type if
|
|
236
|
+
* already the narrowest).
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* If type is `u8c`, returns `u8`.
|
|
240
|
+
*
|
|
241
|
+
* @param t
|
|
242
|
+
*/
|
|
243
|
+
export declare const narrowUint: (t: UintType | 'u64') => 'u8' | 'u16' | 'u32';
|
|
244
|
+
/**
|
|
245
|
+
* Returns the next larger {@link UintType} for given type (or the same type if
|
|
246
|
+
* already the widest).
|
|
247
|
+
*
|
|
248
|
+
* @param t
|
|
249
|
+
*/
|
|
250
|
+
export declare const widenUint: (t: UintType) => 'u16' | 'u32' | 'u64';
|
|
251
|
+
/**
|
|
252
|
+
* Returns the next smaller {@link FloatType} for given type (or the same type
|
|
253
|
+
* if already the narrowest).
|
|
254
|
+
*
|
|
255
|
+
* @param t
|
|
256
|
+
*/
|
|
257
|
+
export declare const narrowFloat: (t: FloatType) => string;
|
|
258
|
+
/**
|
|
259
|
+
* Returns the next larger {@link FloatType} for given type (or the same type if
|
|
260
|
+
* already the widest).
|
|
261
|
+
*
|
|
262
|
+
* @param t
|
|
263
|
+
*/
|
|
264
|
+
export declare const widenFloat: (t: FloatType) => string;
|
|
265
|
+
/**
|
|
266
|
+
* Returns the next smaller type (i.e. {@link IntType}, {@link UintType} or
|
|
267
|
+
* {@link FloatType}) for given type (or the same type if already the smallest).
|
|
268
|
+
*
|
|
269
|
+
* @param t
|
|
270
|
+
*/
|
|
271
|
+
export declare const narrowType: (t: Type | BigType) => string;
|
|
272
|
+
/**
|
|
273
|
+
* Returns the next larger type (i.e. {@link IntType}, {@link UintType} or
|
|
274
|
+
* {@link FloatType}) for given type (or the same type if already the widest).
|
|
275
|
+
*
|
|
276
|
+
* @param t
|
|
277
|
+
*/
|
|
278
|
+
export declare const widenType: (t: Type | BigType) => string;
|
|
279
279
|
//# sourceMappingURL=typedarray.d.ts.map
|