@luma.gl/core 9.3.0-alpha.8 → 9.3.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 (63) hide show
  1. package/dist/adapter/device.d.ts +1 -1
  2. package/dist/adapter/device.d.ts.map +1 -1
  3. package/dist/adapter/device.js +3 -2
  4. package/dist/adapter/device.js.map +1 -1
  5. package/dist/adapter/luma.d.ts.map +1 -1
  6. package/dist/adapter/luma.js +2 -1
  7. package/dist/adapter/luma.js.map +1 -1
  8. package/dist/dist.dev.js +328 -173
  9. package/dist/dist.min.js +5 -5
  10. package/dist/factories/bind-group-factory.d.ts.map +1 -1
  11. package/dist/factories/bind-group-factory.js +14 -5
  12. package/dist/factories/bind-group-factory.js.map +1 -1
  13. package/dist/index.cjs +317 -173
  14. package/dist/index.cjs.map +4 -4
  15. package/dist/index.d.ts +2 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/portable/shader-block-writer.d.ts +51 -0
  20. package/dist/portable/shader-block-writer.d.ts.map +1 -0
  21. package/dist/portable/shader-block-writer.js +185 -0
  22. package/dist/portable/shader-block-writer.js.map +1 -0
  23. package/dist/portable/uniform-store.d.ts +52 -20
  24. package/dist/portable/uniform-store.d.ts.map +1 -1
  25. package/dist/portable/uniform-store.js +71 -26
  26. package/dist/portable/uniform-store.js.map +1 -1
  27. package/dist/shadertypes/data-types/data-type-decoder.js +2 -2
  28. package/dist/shadertypes/data-types/data-type-decoder.js.map +1 -1
  29. package/dist/shadertypes/data-types/decode-data-types.js +2 -2
  30. package/dist/shadertypes/data-types/decode-data-types.js.map +1 -1
  31. package/dist/shadertypes/shader-types/shader-block-layout.d.ts +72 -0
  32. package/dist/shadertypes/shader-types/shader-block-layout.d.ts.map +1 -0
  33. package/dist/shadertypes/shader-types/shader-block-layout.js +209 -0
  34. package/dist/shadertypes/shader-types/shader-block-layout.js.map +1 -0
  35. package/dist/shadertypes/texture-types/texture-format-decoder.js +1 -1
  36. package/dist/shadertypes/texture-types/texture-format-decoder.js.map +1 -1
  37. package/dist/shadertypes/texture-types/texture-format-table.js +2 -2
  38. package/dist/shadertypes/texture-types/texture-format-table.js.map +1 -1
  39. package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts.map +1 -1
  40. package/dist/shadertypes/vertex-types/vertex-format-decoder.js +41 -3
  41. package/dist/shadertypes/vertex-types/vertex-format-decoder.js.map +1 -1
  42. package/dist/shadertypes/vertex-types/vertex-formats.d.ts +6 -6
  43. package/dist/shadertypes/vertex-types/vertex-formats.d.ts.map +1 -1
  44. package/package.json +2 -2
  45. package/src/adapter/device.ts +4 -2
  46. package/src/adapter/luma.ts +1 -0
  47. package/src/factories/bind-group-factory.ts +23 -5
  48. package/src/index.ts +7 -1
  49. package/src/portable/shader-block-writer.ts +254 -0
  50. package/src/portable/uniform-store.ts +92 -37
  51. package/src/shadertypes/data-types/data-type-decoder.ts +2 -2
  52. package/src/shadertypes/data-types/decode-data-types.ts +2 -2
  53. package/src/shadertypes/shader-types/shader-block-layout.ts +340 -0
  54. package/src/shadertypes/shader-types/shader-types.ts +5 -5
  55. package/src/shadertypes/texture-types/texture-format-decoder.ts +1 -1
  56. package/src/shadertypes/texture-types/texture-format-table.ts +2 -2
  57. package/src/shadertypes/vertex-types/vertex-format-decoder.ts +47 -3
  58. package/src/shadertypes/vertex-types/vertex-formats.ts +18 -5
  59. package/dist/portable/uniform-buffer-layout.d.ts +0 -42
  60. package/dist/portable/uniform-buffer-layout.d.ts.map +0 -1
  61. package/dist/portable/uniform-buffer-layout.js +0 -274
  62. package/dist/portable/uniform-buffer-layout.js.map +0 -1
  63. package/src/portable/uniform-buffer-layout.ts +0 -384
@@ -0,0 +1,340 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {PrimitiveDataType} from '../data-types/data-types';
6
+ import type {CompositeShaderType, VariableShaderType} from './shader-types';
7
+ import {alignTo} from '../data-types/decode-data-types';
8
+ import {getVariableShaderTypeInfo, resolveVariableShaderTypeAlias} from './shader-type-decoder';
9
+
10
+ /**
11
+ * Describes the packing for one flattened field in a shader block.
12
+ *
13
+ * Offsets, sizes, and strides are expressed in 32-bit words so the result can
14
+ * be consumed directly by typed-array writers.
15
+ */
16
+ export type ShaderBlockLayoutEntry = {
17
+ /** Offset in 32-bit words from the start of the block. */
18
+ offset: number;
19
+ /** Occupied size in 32-bit words, excluding external array stride. */
20
+ size: number;
21
+ /** Number of logical scalar components in the declared value. */
22
+ components: number;
23
+ /** Number of matrix columns, or `1` for scalars and vectors. */
24
+ columns: number;
25
+ /** Number of rows in each column, or vector length for vectors. */
26
+ rows: number;
27
+ /** Distance between matrix columns in 32-bit words. */
28
+ columnStride: number;
29
+ /** Canonical shader type after alias resolution. */
30
+ shaderType: VariableShaderType;
31
+ /** Scalar data type used to write the value. */
32
+ type: PrimitiveDataType;
33
+ };
34
+
35
+ /**
36
+ * Options for {@link makeShaderBlockLayout}.
37
+ */
38
+ export type ShaderBlockLayoutOptions = {
39
+ /**
40
+ * Packing rules to apply when building the layout.
41
+ *
42
+ * Defaults to `'std140'`.
43
+ */
44
+ layout?: 'std140' | 'wgsl-uniform' | 'wgsl-storage';
45
+ };
46
+
47
+ /**
48
+ * Immutable layout metadata for a uniform or storage-style shader block.
49
+ */
50
+ export type ShaderBlockLayout = {
51
+ /** Packing rules used when this layout was created. */
52
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage';
53
+ /** Exact number of packed bytes required by the block. */
54
+ byteLength: number;
55
+ /** Original composite shader type declarations keyed by top-level field. */
56
+ uniformTypes: Record<string, CompositeShaderType>;
57
+ /** Flattened leaf field layouts keyed by field path. */
58
+ fields: Record<string, ShaderBlockLayoutEntry>;
59
+ };
60
+
61
+ /**
62
+ * Builds a deterministic shader-block layout from composite shader type declarations.
63
+ *
64
+ * The returned value is pure layout metadata. It records the packed field
65
+ * offsets and exact packed byte length, but it does not allocate buffers or
66
+ * serialize values.
67
+ */
68
+ export function makeShaderBlockLayout(
69
+ uniformTypes: Readonly<Record<string, CompositeShaderType>>,
70
+ options: ShaderBlockLayoutOptions = {}
71
+ ): ShaderBlockLayout {
72
+ const copiedUniformTypes = {...uniformTypes};
73
+ const layout = options.layout ?? 'std140';
74
+ const fields: Record<string, ShaderBlockLayoutEntry> = {};
75
+
76
+ let size = 0;
77
+ for (const [key, uniformType] of Object.entries(copiedUniformTypes)) {
78
+ size = addToLayout(fields, key, uniformType, size, layout);
79
+ }
80
+
81
+ size = alignTo(size, getTypeAlignment(copiedUniformTypes, layout));
82
+
83
+ return {
84
+ layout,
85
+ byteLength: size * 4,
86
+ uniformTypes: copiedUniformTypes,
87
+ fields
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Returns the layout metadata for a scalar, vector, or matrix leaf type.
93
+ *
94
+ * The result includes both the occupied size in 32-bit words and the alignment
95
+ * requirement that must be applied before placing the value in a shader block.
96
+ */
97
+ export function getLeafLayoutInfo(
98
+ type: VariableShaderType,
99
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
100
+ ): Omit<ShaderBlockLayoutEntry, 'offset'> & {alignment: 1 | 2 | 4} {
101
+ const resolvedType = resolveVariableShaderTypeAlias(type);
102
+ const decodedType = getVariableShaderTypeInfo(resolvedType);
103
+ const matrixMatch = /^mat(\d)x(\d)<.+>$/.exec(resolvedType);
104
+
105
+ if (matrixMatch) {
106
+ const columns = Number(matrixMatch[1]);
107
+ const rows = Number(matrixMatch[2]);
108
+ const columnInfo = getVectorLayoutInfo(
109
+ rows as 2 | 3 | 4,
110
+ resolvedType,
111
+ decodedType.type,
112
+ layout
113
+ );
114
+ const columnStride = getMatrixColumnStride(columnInfo.size, columnInfo.alignment, layout);
115
+
116
+ return {
117
+ alignment: columnInfo.alignment,
118
+ size: columns * columnStride,
119
+ components: columns * rows,
120
+ columns,
121
+ rows,
122
+ columnStride,
123
+ shaderType: resolvedType,
124
+ type: decodedType.type
125
+ };
126
+ }
127
+
128
+ const vectorMatch = /^vec(\d)<.+>$/.exec(resolvedType);
129
+ if (vectorMatch) {
130
+ return getVectorLayoutInfo(
131
+ Number(vectorMatch[1]) as 2 | 3 | 4,
132
+ resolvedType,
133
+ decodedType.type,
134
+ layout
135
+ );
136
+ }
137
+
138
+ return {
139
+ alignment: 1,
140
+ size: 1,
141
+ components: 1,
142
+ columns: 1,
143
+ rows: 1,
144
+ columnStride: 1,
145
+ shaderType: resolvedType,
146
+ type: decodedType.type
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Type guard for composite struct declarations.
152
+ */
153
+ export function isCompositeShaderTypeStruct(
154
+ value: CompositeShaderType
155
+ ): value is Record<string, CompositeShaderType> {
156
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
157
+ }
158
+
159
+ /**
160
+ * Recursively adds a composite type to the flattened field map.
161
+ *
162
+ * @returns The next free 32-bit-word offset after the inserted type.
163
+ */
164
+ function addToLayout(
165
+ fields: Record<string, ShaderBlockLayoutEntry>,
166
+ name: string,
167
+ type: CompositeShaderType,
168
+ offset: number,
169
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
170
+ ): number {
171
+ if (typeof type === 'string') {
172
+ const info = getLeafLayoutInfo(type, layout);
173
+ const alignedOffset = alignTo(offset, info.alignment);
174
+ fields[name] = {
175
+ offset: alignedOffset,
176
+ ...info
177
+ };
178
+ return alignedOffset + info.size;
179
+ }
180
+
181
+ if (Array.isArray(type)) {
182
+ if (Array.isArray(type[0])) {
183
+ throw new Error(`Nested arrays are not supported for ${name}`);
184
+ }
185
+
186
+ const elementType = type[0] as CompositeShaderType;
187
+ const length = type[1] as number;
188
+ const stride = getArrayStride(elementType, layout);
189
+ const arrayOffset = alignTo(offset, getTypeAlignment(type, layout));
190
+
191
+ for (let i = 0; i < length; i++) {
192
+ addToLayout(fields, `${name}[${i}]`, elementType, arrayOffset + i * stride, layout);
193
+ }
194
+ return arrayOffset + stride * length;
195
+ }
196
+
197
+ if (isCompositeShaderTypeStruct(type)) {
198
+ const structAlignment = getTypeAlignment(type, layout);
199
+ let structOffset = alignTo(offset, structAlignment);
200
+ for (const [memberName, memberType] of Object.entries(type)) {
201
+ structOffset = addToLayout(fields, `${name}.${memberName}`, memberType, structOffset, layout);
202
+ }
203
+ return alignTo(structOffset, structAlignment);
204
+ }
205
+
206
+ throw new Error(`Unsupported CompositeShaderType for ${name}`);
207
+ }
208
+
209
+ /**
210
+ * Returns the occupied size of a composite type in 32-bit words.
211
+ */
212
+ function getTypeSize(
213
+ type: CompositeShaderType,
214
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
215
+ ): number {
216
+ if (typeof type === 'string') {
217
+ return getLeafLayoutInfo(type, layout).size;
218
+ }
219
+
220
+ if (Array.isArray(type)) {
221
+ const elementType = type[0] as CompositeShaderType;
222
+ const length = type[1] as number;
223
+
224
+ if (Array.isArray(elementType)) {
225
+ throw new Error('Nested arrays are not supported');
226
+ }
227
+
228
+ return getArrayStride(elementType, layout) * length;
229
+ }
230
+
231
+ let size = 0;
232
+ for (const memberType of Object.values(type)) {
233
+ const compositeMemberType = memberType as CompositeShaderType;
234
+ size = alignTo(size, getTypeAlignment(compositeMemberType, layout));
235
+ size += getTypeSize(compositeMemberType, layout);
236
+ }
237
+
238
+ return alignTo(size, getTypeAlignment(type, layout));
239
+ }
240
+
241
+ /**
242
+ * Returns the required alignment of a composite type in 32-bit words.
243
+ */
244
+ function getTypeAlignment(
245
+ type: CompositeShaderType,
246
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
247
+ ): 1 | 2 | 4 {
248
+ if (typeof type === 'string') {
249
+ return getLeafLayoutInfo(type, layout).alignment;
250
+ }
251
+
252
+ if (Array.isArray(type)) {
253
+ const elementType = type[0] as CompositeShaderType;
254
+ const elementAlignment = getTypeAlignment(elementType, layout);
255
+ return uses16ByteArrayAlignment(layout)
256
+ ? (Math.max(elementAlignment, 4) as 1 | 2 | 4)
257
+ : elementAlignment;
258
+ }
259
+
260
+ let maxAlignment: 1 | 2 | 4 = 1;
261
+ for (const memberType of Object.values(type)) {
262
+ const memberAlignment = getTypeAlignment(memberType as CompositeShaderType, layout);
263
+ maxAlignment = Math.max(maxAlignment, memberAlignment) as 1 | 2 | 4;
264
+ }
265
+
266
+ return uses16ByteStructAlignment(layout)
267
+ ? (Math.max(maxAlignment, 4) as 1 | 2 | 4)
268
+ : maxAlignment;
269
+ }
270
+
271
+ /**
272
+ * Returns the layout metadata for a vector leaf type.
273
+ */
274
+ function getVectorLayoutInfo(
275
+ components: 2 | 3 | 4,
276
+ shaderType: VariableShaderType,
277
+ type: PrimitiveDataType,
278
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
279
+ ): Omit<ShaderBlockLayoutEntry, 'offset'> & {alignment: 1 | 2 | 4} {
280
+ return {
281
+ alignment: components === 2 ? 2 : 4,
282
+ size: components === 3 ? 3 : components,
283
+ components,
284
+ columns: 1,
285
+ rows: components,
286
+ columnStride: components === 3 ? 3 : components,
287
+ shaderType,
288
+ type
289
+ };
290
+ }
291
+
292
+ /**
293
+ * Returns the stride of an array element in 32-bit words.
294
+ *
295
+ * This includes any layout-specific padding between adjacent array elements.
296
+ */
297
+ function getArrayStride(
298
+ elementType: CompositeShaderType,
299
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
300
+ ): number {
301
+ const elementSize = getTypeSize(elementType, layout);
302
+ const elementAlignment = getTypeAlignment(elementType, layout);
303
+ return getArrayLikeStride(elementSize, elementAlignment, layout);
304
+ }
305
+
306
+ /**
307
+ * Returns the common stride rule shared by array-like elements in the target layout.
308
+ */
309
+ function getArrayLikeStride(
310
+ size: number,
311
+ alignment: 1 | 2 | 4,
312
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
313
+ ): number {
314
+ return alignTo(size, uses16ByteArrayAlignment(layout) ? 4 : alignment);
315
+ }
316
+
317
+ /**
318
+ * Returns the stride of a matrix column in 32-bit words.
319
+ */
320
+ function getMatrixColumnStride(
321
+ size: number,
322
+ alignment: 1 | 2 | 4,
323
+ layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'
324
+ ): number {
325
+ return layout === 'std140' ? 4 : alignTo(size, alignment);
326
+ }
327
+
328
+ /**
329
+ * Returns `true` when arrays must be rounded up to 16-byte boundaries.
330
+ */
331
+ function uses16ByteArrayAlignment(layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'): boolean {
332
+ return layout === 'std140' || layout === 'wgsl-uniform';
333
+ }
334
+
335
+ /**
336
+ * Returns `true` when structs must be rounded up to 16-byte boundaries.
337
+ */
338
+ function uses16ByteStructAlignment(layout: 'std140' | 'wgsl-uniform' | 'wgsl-storage'): boolean {
339
+ return layout === 'std140' || layout === 'wgsl-uniform';
340
+ }
@@ -59,7 +59,7 @@ export type ArrayShaderType = readonly [type: CompositeShaderType, length: numbe
59
59
  export type AttributeShaderTypeAlias = keyof AttributeShaderTypeAliasMap;
60
60
 
61
61
  /** @note work around for lack of type narrowing in conditional generics */
62
- // prettier-ignore
62
+ // biome-ignore format: preserve layout
63
63
  type AttributeShaderTypeAliasMap = {
64
64
  vec2f: 'vec2<f32>';
65
65
  vec3f: 'vec3<f32>';
@@ -79,7 +79,7 @@ type AttributeShaderTypeAliasMap = {
79
79
  export type VariableShaderTypeAlias = keyof VariableShaderTypeAliasMap;
80
80
 
81
81
  /** @note work around for lack of type narrowing in conditional generics */
82
- // prettier-ignore
82
+ // biome-ignore format: preserve layout
83
83
  type VariableShaderTypeAliasMap = {
84
84
  // Vector aliases
85
85
  vec2f: 'vec2<f32>';
@@ -149,7 +149,7 @@ export type VariableShaderTypeT<T extends VariableShaderType | keyof VariableSha
149
149
 
150
150
  // HELPER TYPES
151
151
 
152
- // prettier-ignore
152
+ // biome-ignore format: preserve layout
153
153
  type TypeOfAliasSuffix<T extends string> =
154
154
  T extends 'f' ? 'f32' :
155
155
  T extends 'i' ? 'i32' :
@@ -157,14 +157,14 @@ type TypeOfAliasSuffix<T extends string> =
157
157
  T extends 'h' ? 'f16' :
158
158
  never;
159
159
 
160
- // prettier-ignore
160
+ // biome-ignore format: preserve layout
161
161
  export type AttributeShaderTypeAliasT<T extends AttributeShaderTypeAlias> =
162
162
  T extends `vec2${infer S}` ? `vec2<${TypeOfAliasSuffix<S>}>` :
163
163
  T extends `vec3${infer S}` ? `vec3<${TypeOfAliasSuffix<S>}>` :
164
164
  T extends `vec4${infer S}` ? `vec4<${TypeOfAliasSuffix<S>}>` :
165
165
  never;
166
166
 
167
- // prettier-ignore
167
+ // biome-ignore format: preserve layout
168
168
  export type VariableShaderTypeAliasT<T extends VariableShaderTypeAlias> =
169
169
  T extends `vec2${infer S}` ? `vec2<${TypeOfAliasSuffix<S>}>` :
170
170
  T extends `vec3${infer S}` ? `vec3<${TypeOfAliasSuffix<S>}>` :
@@ -18,7 +18,7 @@ import {getTextureFormatDefinition} from './texture-format-table';
18
18
  const RGB_FORMAT_REGEX = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;
19
19
  const COLOR_FORMAT_PREFIXES = ['rgb', 'rgba', 'bgra'];
20
20
  const DEPTH_FORMAT_PREFIXES = ['depth', 'stencil'];
21
- // prettier-ignore
21
+ // biome-ignore format: preserve layout
22
22
  const COMPRESSED_TEXTURE_FORMAT_PREFIXES = [
23
23
  'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7', 'etc1', 'etc2', 'eac', 'atc', 'astc', 'pvrtc'
24
24
  ];
@@ -68,7 +68,7 @@ export function getTextureFormatTable(): Readonly<Record<TextureFormat, TextureF
68
68
  return TEXTURE_FORMAT_TABLE;
69
69
  }
70
70
 
71
- // prettier-ignore
71
+ // biome-ignore format: preserve layout
72
72
  const TEXTURE_FORMAT_COLOR_DEPTH_TABLE: Readonly<Record<TextureFormatColorUncompressed | TextureFormatDepthStencil, TextureFormatDefinition>> = {
73
73
  // 8-bit formats
74
74
  'r8unorm': {},
@@ -153,7 +153,7 @@ const TEXTURE_FORMAT_COLOR_DEPTH_TABLE: Readonly<Record<TextureFormatColorUncomp
153
153
  'depth32float-stencil8': {attachment: 'depth-stencil', bitsPerChannel: [32, 8, 0, 0], packed: true},
154
154
  };
155
155
 
156
- // prettier-ignore
156
+ // biome-ignore format: preserve layout
157
157
  const TEXTURE_FORMAT_COMPRESSED_TABLE: Readonly<Record<TextureFormatCompressed, TextureFormatDefinition>> = {
158
158
 
159
159
  // BC compressed formats: check device.features.has("texture-compression-bc");
@@ -49,7 +49,7 @@ export class VertexFormatDecoder {
49
49
  : signedDataType;
50
50
 
51
51
  switch (dataType) {
52
- // TODO - Special cases for WebGL (not supported on WebGPU), overrides the check below
52
+ // Special cases for WebGL-only x3 formats that WebGPU does not support.
53
53
  case 'unorm8':
54
54
  if (components === 1) {
55
55
  return 'unorm8';
@@ -60,14 +60,58 @@ export class VertexFormatDecoder {
60
60
  return `${dataType}x${components}`;
61
61
 
62
62
  case 'snorm8':
63
+ if (components === 1) {
64
+ return 'snorm8';
65
+ }
66
+ if (components === 3) {
67
+ return 'snorm8x3-webgl';
68
+ }
69
+ return `${dataType}x${components}`;
70
+
63
71
  case 'uint8':
64
72
  case 'sint8':
65
- // WebGPU 8 bit formats must be aligned to 16 bit boundaries');
66
- // fall through
73
+ // WebGPU 8 bit formats must be aligned to 16 bit boundaries.
74
+ if (components === 1 || components === 3) {
75
+ throw new Error(`size: ${components}`);
76
+ }
77
+ return `${dataType}x${components}`;
78
+
67
79
  case 'uint16':
80
+ if (components === 1) {
81
+ return 'uint16';
82
+ }
83
+ if (components === 3) {
84
+ return 'uint16x3-webgl';
85
+ }
86
+ return `${dataType}x${components}`;
87
+
68
88
  case 'sint16':
89
+ if (components === 1) {
90
+ return 'sint16';
91
+ }
92
+ if (components === 3) {
93
+ return 'sint16x3-webgl';
94
+ }
95
+ return `${dataType}x${components}`;
96
+
69
97
  case 'unorm16':
98
+ if (components === 1) {
99
+ return 'unorm16';
100
+ }
101
+ if (components === 3) {
102
+ return 'unorm16x3-webgl';
103
+ }
104
+ return `${dataType}x${components}`;
105
+
70
106
  case 'snorm16':
107
+ if (components === 1) {
108
+ return 'snorm16';
109
+ }
110
+ if (components === 3) {
111
+ return 'snorm16x3-webgl';
112
+ }
113
+ return `${dataType}x${components}`;
114
+
71
115
  case 'float16':
72
116
  // WebGPU 16 bit formats must be aligned to 32 bit boundaries
73
117
  if (components === 1 || components === 3) {
@@ -39,12 +39,16 @@ export type VertexFormat =
39
39
  | 'unorm16' // Chrome 133+
40
40
  | 'snorm16' // Chrome 133+
41
41
  | 'uint16x2'
42
+ | 'uint16x3-webgl' // Not in WebGPU
42
43
  | 'uint16x4'
43
44
  | 'sint16x2'
45
+ | 'sint16x3-webgl' // Not in WebGPU
44
46
  | 'sint16x4'
45
47
  | 'unorm16x2'
48
+ | 'unorm16x3-webgl' // Not in WebGPU
46
49
  | 'unorm16x4'
47
50
  | 'snorm16x2'
51
+ | 'snorm16x3-webgl' // Not in WebGPU
48
52
  | 'snorm16x4'
49
53
  // 32 bit integers
50
54
  | 'uint32'
@@ -143,10 +147,10 @@ type VertexFormatUnorm8 =
143
147
  | 'unorm8x4-bgra'
144
148
  | 'unorm10-10-10-2';
145
149
  type VertexFormatSnorm8 = 'snorm8' | 'snorm8x2' | 'snorm8x3-webgl' | 'snorm8x4';
146
- type VertexFormatUint16 = 'uint16' | 'uint16x2' | 'uint16x4';
147
- type VertexFormatSint16 = 'sint16' | 'sint16x2' | 'sint16x4';
148
- type VertexFormatUnorm16 = 'unorm16' | 'unorm16x2' | 'unorm16x4';
149
- type VertexFormatSnorm16 = 'snorm16' | 'snorm16x2' | 'snorm16x4';
150
+ type VertexFormatUint16 = 'uint16' | 'uint16x2' | 'uint16x3-webgl' | 'uint16x4';
151
+ type VertexFormatSint16 = 'sint16' | 'sint16x2' | 'sint16x3-webgl' | 'sint16x4';
152
+ type VertexFormatUnorm16 = 'unorm16' | 'unorm16x2' | 'unorm16x3-webgl' | 'unorm16x4';
153
+ type VertexFormatSnorm16 = 'snorm16' | 'snorm16x2' | 'snorm16x3-webgl' | 'snorm16x4';
150
154
  type VertexFormatUint32 = 'uint32' | 'uint32x2' | 'uint32x3' | 'uint32x4';
151
155
  type VertexFormatSint32 = 'sint32' | 'sint32x2' | 'sint32x3' | 'sint32x4';
152
156
  type VertexFormatFloat16 = 'float16' | 'float16x2' | 'float16x4';
@@ -165,7 +169,16 @@ type VertexFormat2Components =
165
169
  | 'sint32x2'
166
170
  | 'float16x2'
167
171
  | 'float32x2';
168
- type VertexFormat3Components = 'unorm8x3-webgl' | 'uint32x3' | 'sint32x3' | 'float32x3';
172
+ type VertexFormat3Components =
173
+ | 'unorm8x3-webgl'
174
+ | 'snorm8x3-webgl'
175
+ | 'uint16x3-webgl'
176
+ | 'sint16x3-webgl'
177
+ | 'unorm16x3-webgl'
178
+ | 'snorm16x3-webgl'
179
+ | 'uint32x3'
180
+ | 'sint32x3'
181
+ | 'float32x3';
169
182
  type VertexFormat4Components =
170
183
  | 'uint8x4'
171
184
  | 'sint8x4'
@@ -1,42 +0,0 @@
1
- import type { PrimitiveDataType } from "../shadertypes/data-types/data-types.js";
2
- import type { CompositeShaderType, VariableShaderType } from "../shadertypes/shader-types/shader-types.js";
3
- import type { CompositeUniformValue, UniformValue } from "../adapter/types/uniforms.js";
4
- type UniformLayoutEntry = {
5
- offset: number;
6
- size: number;
7
- components: number;
8
- columns: number;
9
- rows: number;
10
- shaderType: VariableShaderType;
11
- type: PrimitiveDataType;
12
- };
13
- export type UniformValues = Record<string, CompositeUniformValue>;
14
- /**
15
- * Std140 layout for uniform buffers
16
- * Supports manual listing of uniforms
17
- */
18
- export declare class UniformBufferLayout {
19
- readonly layout: Record<string, UniformLayoutEntry>;
20
- readonly uniformTypes: Record<string, CompositeShaderType>;
21
- /** number of bytes needed for buffer allocation */
22
- readonly byteLength: number;
23
- /** Create a new UniformBufferLayout given a map of attributes. */
24
- constructor(uniformTypes: Readonly<Record<string, CompositeShaderType>>);
25
- /** Does this layout have a field with specified name */
26
- has(name: string): boolean;
27
- /** Get offset and size for a field with specified name */
28
- get(name: string): {
29
- offset: number;
30
- size: number;
31
- } | undefined;
32
- /** Flatten nested uniform values into leaf-path values understood by UniformBlock. */
33
- getFlatUniformValues(uniformValues: Readonly<UniformValues>): Record<string, UniformValue>;
34
- /** Get the data for the complete buffer */
35
- getData(uniformValues: Readonly<UniformValues>): Uint8Array;
36
- private _addToLayout;
37
- private _flattenCompositeValue;
38
- private _flattenPackedArray;
39
- private _writeLeafValue;
40
- }
41
- export {};
42
- //# sourceMappingURL=uniform-buffer-layout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uniform-buffer-layout.d.ts","sourceRoot":"","sources":["../../src/portable/uniform-buffer-layout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAC,gDAA6C;AAC5E,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,oDAAiD;AAOlD,OAAO,KAAK,EAAC,qBAAqB,EAAE,YAAY,EAAC,qCAAkC;AAKnF,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,kBAAkB,CAAC;IAC/B,IAAI,EAAE,iBAAiB,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAQlE;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAM;IACzD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAE3D,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,kEAAkE;gBACtD,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAavE,wDAAwD;IACxD,GAAG,CAAC,IAAI,EAAE,MAAM;IAIhB,0DAA0D;IAC1D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,GAAG,SAAS;IAK7D,sFAAsF;IACtF,oBAAoB,CAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAe1F,2CAA2C;IAC3C,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,UAAU;IAmB3D,OAAO,CAAC,YAAY;IAsCpB,OAAO,CAAC,sBAAsB;IAgE9B,OAAO,CAAC,mBAAmB;IA6B3B,OAAO,CAAC,eAAe;CAoCxB"}