@luma.gl/core 9.2.5 → 9.3.0-alpha.2

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 (74) hide show
  1. package/dist/adapter/canvas-context.d.ts +22 -3
  2. package/dist/adapter/canvas-context.d.ts.map +1 -1
  3. package/dist/adapter/canvas-context.js +39 -8
  4. package/dist/adapter/canvas-context.js.map +1 -1
  5. package/dist/adapter/device.d.ts +5 -5
  6. package/dist/adapter/device.d.ts.map +1 -1
  7. package/dist/adapter/device.js +17 -2
  8. package/dist/adapter/device.js.map +1 -1
  9. package/dist/adapter/luma.js +1 -1
  10. package/dist/adapter/luma.js.map +1 -1
  11. package/dist/adapter/resources/buffer.d.ts +4 -4
  12. package/dist/adapter/resources/buffer.d.ts.map +1 -1
  13. package/dist/adapter/resources/buffer.js +4 -1
  14. package/dist/adapter/resources/buffer.js.map +1 -1
  15. package/dist/adapter/resources/fence.d.ts +16 -0
  16. package/dist/adapter/resources/fence.d.ts.map +1 -0
  17. package/dist/adapter/resources/fence.js +15 -0
  18. package/dist/adapter/resources/fence.js.map +1 -0
  19. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  20. package/dist/adapter/resources/framebuffer.js +6 -1
  21. package/dist/adapter/resources/framebuffer.js.map +1 -1
  22. package/dist/adapter/resources/resource.d.ts +5 -0
  23. package/dist/adapter/resources/resource.d.ts.map +1 -1
  24. package/dist/adapter/resources/resource.js +3 -0
  25. package/dist/adapter/resources/resource.js.map +1 -1
  26. package/dist/adapter/resources/texture.d.ts +97 -24
  27. package/dist/adapter/resources/texture.d.ts.map +1 -1
  28. package/dist/adapter/resources/texture.js +116 -10
  29. package/dist/adapter/resources/texture.js.map +1 -1
  30. package/dist/dist.dev.js +382 -105
  31. package/dist/dist.min.js +6 -6
  32. package/dist/index.cjs +371 -102
  33. package/dist/index.cjs.map +4 -4
  34. package/dist/index.d.ts +5 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/portable/uniform-buffer-layout.d.ts +13 -4
  39. package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
  40. package/dist/portable/uniform-buffer-layout.js +88 -55
  41. package/dist/portable/uniform-buffer-layout.js.map +1 -1
  42. package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -1
  43. package/dist/shadertypes/data-types/decode-data-types.js +2 -1
  44. package/dist/shadertypes/data-types/decode-data-types.js.map +1 -1
  45. package/dist/shadertypes/data-types/shader-types.d.ts +5 -7
  46. package/dist/shadertypes/data-types/shader-types.d.ts.map +1 -1
  47. package/dist/shadertypes/textures/texture-format-decoder.d.ts +25 -8
  48. package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +1 -1
  49. package/dist/shadertypes/textures/texture-format-decoder.js +58 -32
  50. package/dist/shadertypes/textures/texture-format-decoder.js.map +1 -1
  51. package/dist/shadertypes/textures/texture-formats.d.ts +43 -16
  52. package/dist/shadertypes/textures/texture-formats.d.ts.map +1 -1
  53. package/dist/shadertypes/textures/texture-formats.js.map +1 -1
  54. package/dist/shadertypes/textures/texture-layout.d.ts +5 -0
  55. package/dist/shadertypes/textures/texture-layout.d.ts.map +1 -0
  56. package/dist/shadertypes/textures/texture-layout.js +41 -0
  57. package/dist/shadertypes/textures/texture-layout.js.map +1 -0
  58. package/package.json +2 -2
  59. package/src/adapter/canvas-context.ts +47 -13
  60. package/src/adapter/device.ts +27 -5
  61. package/src/adapter/resources/buffer.ts +6 -4
  62. package/src/adapter/resources/command-buffer.ts +1 -1
  63. package/src/adapter/resources/command-encoder.ts +2 -2
  64. package/src/adapter/resources/fence.ts +30 -0
  65. package/src/adapter/resources/framebuffer.ts +6 -1
  66. package/src/adapter/resources/resource.ts +5 -0
  67. package/src/adapter/resources/texture.ts +174 -26
  68. package/src/index.ts +11 -2
  69. package/src/portable/uniform-buffer-layout.ts +122 -63
  70. package/src/shadertypes/data-types/decode-data-types.ts +2 -1
  71. package/src/shadertypes/data-types/shader-types.ts +14 -7
  72. package/src/shadertypes/textures/texture-format-decoder.ts +95 -40
  73. package/src/shadertypes/textures/texture-formats.ts +54 -15
  74. package/src/shadertypes/textures/texture-layout.ts +60 -0
@@ -1,4 +1,4 @@
1
- import { NormalizedDataType } from "../data-types/data-types.js";
1
+ import { NormalizedDataType, DataTypeArray, NormalizedDataTypeArray } from "../data-types/data-types.js";
2
2
  /** Information about the structure of a texture format */
3
3
  export type TextureFormatInfo = {
4
4
  /** The format that is described */
@@ -51,6 +51,32 @@ export type TextureFormatCapabilities = {
51
51
  /** If a feature string, the specified device feature determines if format is storeable. */
52
52
  store: TextureFeature | boolean;
53
53
  };
54
+ /**
55
+ * Memory layout for reading/writing data to a texture's memory.
56
+ *
57
+ * @note Due to alignment, GPU texture data is typically not contiguous.
58
+ *
59
+ * @note GPU texure data must be accessed according to this layout.
60
+ * - On CPU, only the range of rows that are actually read or written need to be allocated.
61
+ * - However, space for the full, padded/aligned rows must be allocated in the buffer,
62
+ * even if just a partial horizontal range `{x, width}` is actually read or written.
63
+ *
64
+ * @note byteLength = bytesPerRow * rowsPerImage * depthOrArrayLayers.
65
+ */
66
+ export type TextureMemoryLayout = {
67
+ /** Total length in bytes */
68
+ byteLength: number;
69
+ /** Number of images */
70
+ depthOrArrayLayers: number;
71
+ /** Stride between successive images (Use when depthOrArrayLayers > 1) */
72
+ bytesPerImage: number;
73
+ /** Number of rows per image */
74
+ rowsPerImage: number;
75
+ /** Number of bytes per row (padded) */
76
+ bytesPerRow: number;
77
+ /** Number of bytes per pixel */
78
+ bytesPerPixel: number;
79
+ };
54
80
  /**
55
81
  * These represent the main compressed texture formats
56
82
  * Each format typically has a number of more specific subformats
@@ -70,21 +96,22 @@ export type TextureFormatDepthStencil = 'stencil8' | 'depth16unorm' | 'depth24pl
70
96
  /** Texture formats for color attachments */
71
97
  export type TextureFormatColor = TextureFormatColorUncompressed | TextureFormatCompressed;
72
98
  export type TextureFormatColorUncompressed = TextureFormatUnorm8 | TextureFormatSnorm8 | TextureFormatUint8 | TextureFormatSint8 | TextureFormatUnorm16 | TextureFormatSnorm16 | TextureFormatUint16 | TextureFormatSint16 | TextureFormatFloat16 | TextureFormatUint32 | TextureFormatSint32 | TextureFormatFloat32 | TextureFormatPacked16 | TextureFormatPacked32;
73
- type TextureFormatUnorm8 = 'r8unorm' | 'rg8unorm' | 'rgb8unorm-webgl' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'bgra8unorm' | 'bgra8unorm-srgb';
74
- type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
75
- type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
76
- type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
77
- type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
78
- type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
79
- type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
80
- type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
81
- type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
82
- type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
83
- type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
84
- type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
85
- type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
86
- type TextureFormatPacked32 = 'rgb9e5ufloat' | 'rg11b10ufloat' | 'rgb10a2unorm' | 'rgb10a2uint';
99
+ export type TextureFormatUnorm8 = 'r8unorm' | 'rg8unorm' | 'rgb8unorm-webgl' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'bgra8unorm' | 'bgra8unorm-srgb';
100
+ export type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
101
+ export type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
102
+ export type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
103
+ export type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
104
+ export type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
105
+ export type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
106
+ export type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
107
+ export type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
108
+ export type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
109
+ export type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
110
+ export type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
111
+ export type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
112
+ export type TextureFormatPacked32 = 'rgb9e5ufloat' | 'rg11b10ufloat' | 'rgb10a2unorm' | 'rgb10a2uint';
87
113
  export type TextureFormatCompressed = 'bc1-rgb-unorm-webgl' | 'bc1-rgb-unorm-srgb-webgl' | 'pvrtc-rgb4unorm-webgl' | 'pvrtc-rgba4unorm-webgl' | 'pvrtc-rbg2unorm-webgl' | 'pvrtc-rgba2unorm-webgl' | 'etc1-rbg-unorm-webgl' | 'atc-rgb-unorm-webgl' | 'atc-rgba-unorm-webgl' | 'atc-rgbai-unorm-webgl' | 'bc1-rgba-unorm' | 'bc1-rgba-unorm-srgb' | 'bc2-rgba-unorm' | 'bc2-rgba-unorm-srgb' | 'bc3-rgba-unorm' | 'bc3-rgba-unorm-srgb' | 'bc4-r-unorm' | 'bc4-r-snorm' | 'bc5-rg-unorm' | 'bc5-rg-snorm' | 'bc6h-rgb-ufloat' | 'bc6h-rgb-float' | 'bc7-rgba-unorm' | 'bc7-rgba-unorm-srgb' | 'etc2-rgb8unorm' | 'etc2-rgb8unorm-srgb' | 'etc2-rgb8a1unorm' | 'etc2-rgb8a1unorm-srgb' | 'etc2-rgba8unorm' | 'etc2-rgba8unorm-srgb' | 'eac-r11unorm' | 'eac-r11snorm' | 'eac-rg11unorm' | 'eac-rg11snorm' | 'astc-4x4-unorm' | 'astc-4x4-unorm-srgb' | 'astc-5x4-unorm' | 'astc-5x4-unorm-srgb' | 'astc-5x5-unorm' | 'astc-5x5-unorm-srgb' | 'astc-6x5-unorm' | 'astc-6x5-unorm-srgb' | 'astc-6x6-unorm' | 'astc-6x6-unorm-srgb' | 'astc-8x5-unorm' | 'astc-8x5-unorm-srgb' | 'astc-8x6-unorm' | 'astc-8x6-unorm-srgb' | 'astc-8x8-unorm' | 'astc-8x8-unorm-srgb' | 'astc-10x5-unorm' | 'astc-10x5-unorm-srgb' | 'astc-10x6-unorm' | 'astc-10x6-unorm-srgb' | 'astc-10x8-unorm' | 'astc-10x8-unorm-srgb' | 'astc-10x10-unorm' | 'astc-10x10-unorm-srgb' | 'astc-12x10-unorm' | 'astc-12x10-unorm-srgb' | 'astc-12x12-unorm' | 'astc-12x12-unorm-srgb';
114
+ export type TextureFormatTypedArray<T extends TextureFormat> = DataTypeArray<TextureFormatDataType<T>>;
115
+ export type TextureFormatNormalizedTypedArray<T extends TextureFormat> = NormalizedDataTypeArray<TextureFormatDataType<T>>;
88
116
  export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFormatUint8 ? 'uint8' : T extends TextureFormatSint8 ? 'sint8' : T extends TextureFormatUnorm8 ? 'unorm8' : T extends TextureFormatSnorm8 ? 'snorm8' : T extends TextureFormatUint16 ? 'uint16' : T extends TextureFormatSint16 ? 'sint16' : T extends TextureFormatUnorm16 ? 'unorm16' : T extends TextureFormatSnorm16 ? 'snorm16' : T extends TextureFormatUint32 ? 'uint32' : T extends TextureFormatSint32 ? 'sint32' : T extends TextureFormatFloat16 ? 'float16' : T extends TextureFormatFloat32 ? 'float32' : T extends TextureFormatDepthStencil ? 'uint32' : T extends TextureFormatCompressed ? 'uint8' : T extends TextureFormatPacked16 ? 'uint16' : T extends TextureFormatPacked32 ? 'uint32' : never;
89
- export {};
90
117
  //# sourceMappingURL=texture-formats.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"texture-formats.d.ts","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,kBAAkB,EAAC,oCAAiC;AAE5D,0DAA0D;AAC1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mCAAmC;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB,gDAAgD;IAChD,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,eAAe,CAAC;IAC7D,wDAAwD;IACxD,QAAQ,EAAE,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/C,4DAA4D;IAC5D,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,gCAAgC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,MAAM,EAAE,OAAO,CAAC;IAChB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GAC/B,OAAO,GACP,CAAC,SAAS,qBAAqB,GAC7B,QAAQ,GACR,CAAC,SAAS,qBAAqB,GAC7B,QAAQ,GACR,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"texture-formats.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;;AAuRpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDE"}
1
+ {"version":3,"file":"texture-formats.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;;AA8TpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDE"}
@@ -0,0 +1,5 @@
1
+ import { TypedArray } from '@math.gl/types';
2
+ import { type TextureFormat, type TextureMemoryLayout } from "./texture-formats.js";
3
+ export declare function getTextureImageView<T extends TextureFormat>(arrayBuffer: ArrayBuffer, memoryLayout: TextureMemoryLayout, format: T, image?: number): Uint32Array<ArrayBuffer> | Uint16Array<ArrayBuffer> | Uint8Array<ArrayBuffer> | Float32Array<ArrayBuffer>;
4
+ export declare function setTextureImageData<T extends TextureFormat>(arrayBuffer: ArrayBuffer, memoryLayout: TextureMemoryLayout, format: T, data: TypedArray, image?: number): void;
5
+ //# sourceMappingURL=texture-layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture-layout.d.ts","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-layout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAC,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAC,6BAA0B;AAG/E,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,EACzD,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,CAAC,EACT,KAAK,SAAI,6GA8BV;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,EACzD,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,UAAU,EAChB,KAAK,SAAI,GACR,IAAI,CASN"}
@@ -0,0 +1,41 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { textureFormatDecoder } from "./texture-format-decoder.js";
5
+ export function getTextureImageView(arrayBuffer, memoryLayout, format, image = 0) {
6
+ const formatInfo = textureFormatDecoder.getInfo(format);
7
+ const bytesPerComponent = formatInfo.bytesPerPixel / formatInfo.components;
8
+ const { bytesPerImage } = memoryLayout;
9
+ const offset = bytesPerImage * image;
10
+ const totalPixels = memoryLayout.bytesPerImage / bytesPerComponent;
11
+ switch (format) {
12
+ case 'rgba8unorm':
13
+ case 'bgra8unorm':
14
+ case 'rgba8uint':
15
+ return new Uint8Array(arrayBuffer, offset, totalPixels);
16
+ case 'r8unorm':
17
+ return new Uint8Array(arrayBuffer, offset, totalPixels);
18
+ case 'r16uint':
19
+ case 'rgba16uint':
20
+ return new Uint16Array(arrayBuffer, offset, totalPixels);
21
+ case 'r32uint':
22
+ case 'rgba32uint':
23
+ return new Uint32Array(arrayBuffer, offset, totalPixels);
24
+ case 'r32float':
25
+ return new Float32Array(arrayBuffer, offset, totalPixels);
26
+ case 'rgba16float':
27
+ return new Uint16Array(arrayBuffer, offset, totalPixels); // 4 channels
28
+ case 'rgba32float':
29
+ return new Float32Array(arrayBuffer, offset, totalPixels);
30
+ default:
31
+ throw new Error(`Unsupported format: ${format}`);
32
+ }
33
+ }
34
+ export function setTextureImageData(arrayBuffer, memoryLayout, format, data, image = 0) {
35
+ const offset = 0; // memoryLayout.bytesPerImage * image;
36
+ const totalPixels = memoryLayout.bytesPerImage / memoryLayout.bytesPerPixel;
37
+ const subArray = data.subarray(0, totalPixels);
38
+ const typedArray = getTextureImageView(arrayBuffer, memoryLayout, format, image);
39
+ typedArray.set(subArray, offset);
40
+ }
41
+ //# sourceMappingURL=texture-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture-layout.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-layout.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAE9D,MAAM,UAAU,mBAAmB,CACjC,WAAwB,EACxB,YAAiC,EACjC,MAAS,EACT,KAAK,GAAG,CAAC;IAET,MAAM,UAAU,GAAG,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,iBAAiB,GAAG,UAAU,CAAC,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC;IAC3E,MAAM,EAAC,aAAa,EAAC,GAAG,YAAY,CAAC;IACrC,MAAM,MAAM,GAAG,aAAa,GAAG,KAAK,CAAC;IACrC,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,GAAG,iBAAiB,CAAC;IAEnE,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,IAAI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,KAAK,SAAS;YACZ,OAAO,IAAI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,KAAK,SAAS,CAAC;QACf,KAAK,YAAY;YACf,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3D,KAAK,SAAS,CAAC;QACf,KAAK,YAAY;YACf,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3D,KAAK,UAAU;YACb,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D,KAAK,aAAa;YAChB,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,aAAa;QACzE,KAAK,aAAa;YAChB,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAwB,EACxB,YAAiC,EACjC,MAAS,EACT,IAAgB,EAChB,KAAK,GAAG,CAAC;IAET,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,sCAAsC;IAExD,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IAC5E,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,mBAAmB,CAAC,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAEjF,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/core",
3
- "version": "9.2.5",
3
+ "version": "9.3.0-alpha.2",
4
4
  "description": "The luma.gl core Device API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,5 +46,5 @@
46
46
  "@probe.gl/stats": "^4.0.8",
47
47
  "@types/offscreencanvas": "^2019.6.4"
48
48
  },
49
- "gitHead": "a8efd26edd0c61c7bb29ea700c6c38f544f60326"
49
+ "gitHead": "7fedf8d8902f58490a4ffca9a873daee3c732f24"
50
50
  }
@@ -106,11 +106,18 @@ export abstract class CanvasContext {
106
106
  /** Height of drawing buffer: automatically tracks this.pixelHeight if props.autoResize is true */
107
107
  drawingBufferHeight: number;
108
108
 
109
+ /** Resolves when the canvas is initialized, i.e. when the ResizeObserver has updated the pixel size */
109
110
  protected _initializedResolvers = withResolvers<void>();
111
+ /** ResizeObserver to track canvas size changes */
110
112
  protected readonly _resizeObserver: ResizeObserver | undefined;
113
+ /** IntersectionObserver to track canvas visibility changes */
111
114
  protected readonly _intersectionObserver: IntersectionObserver | undefined;
112
- protected _position: [number, number];
115
+ /** Position of the canvas in the document, updated by a timer */
116
+ protected _position: [number, number] = [0, 0];
117
+ /** Whether this canvas context has been destroyed */
113
118
  protected destroyed = false;
119
+ /** Whether the drawing buffer size needs to be resized (deferred resizing to avoid flicker) */
120
+ protected _needsDrawingBufferResize: boolean = true;
114
121
 
115
122
  abstract get [Symbol.toStringTag](): string;
116
123
 
@@ -200,9 +207,12 @@ export abstract class CanvasContext {
200
207
  }
201
208
 
202
209
  /** Returns a framebuffer with properly resized current 'swap chain' textures */
203
- abstract getCurrentFramebuffer(options?: {
210
+ getCurrentFramebuffer(options?: {
204
211
  depthStencilFormat?: TextureFormatDepthStencil | false;
205
- }): Framebuffer;
212
+ }): Framebuffer {
213
+ this._resizeDrawingBufferIfNeeded();
214
+ return this._getCurrentFramebuffer(options);
215
+ }
206
216
 
207
217
  // SIZE METHODS
208
218
 
@@ -239,13 +249,17 @@ export abstract class CanvasContext {
239
249
  return [maxTextureDimension, maxTextureDimension];
240
250
  }
241
251
 
242
- /** Update the canvas drawing buffer size. Called automatically if props.autoResize is true. */
252
+ /**
253
+ * Update the canvas drawing buffer size.
254
+ * @note - Called automatically if props.autoResize is true.
255
+ * @note - Defers update of drawing buffer size until framebuffer is requested to avoid flicker
256
+ * (resizing clears the drawing buffer)!
257
+ */
243
258
  setDrawingBufferSize(width: number, height: number) {
244
- this.canvas.width = width;
245
- this.canvas.height = height;
246
-
247
- this.drawingBufferWidth = width;
248
- this.drawingBufferHeight = height;
259
+ // TODO(ib) - temporarily makes drawingBufferWidth/Height out of sync with canvas.width/height, could that cause issues?
260
+ this.drawingBufferWidth = Math.floor(width);
261
+ this.drawingBufferHeight = Math.floor(height);
262
+ this._needsDrawingBufferResize = true;
249
263
  }
250
264
 
251
265
  /**
@@ -311,7 +325,12 @@ export abstract class CanvasContext {
311
325
  * Can be called after changes to size or props,
312
326
  * to give implementation an opportunity to update configurations.
313
327
  */
314
- protected abstract _updateDevice(): void;
328
+ protected abstract _configureDevice(): void;
329
+
330
+ /** Returns a framebuffer with properly resized current 'swap chain' textures */
331
+ protected abstract _getCurrentFramebuffer(options?: {
332
+ depthStencilFormat?: TextureFormatDepthStencil | false;
333
+ }): Framebuffer;
315
334
 
316
335
  // IMPLEMENTATION
317
336
 
@@ -379,6 +398,7 @@ export abstract class CanvasContext {
379
398
  this.device.props.onResize(this, {oldPixelSize});
380
399
  }
381
400
 
401
+ /** Initiate a deferred update for the canvas drawing buffer size */
382
402
  protected _updateDrawingBufferSize() {
383
403
  // Update the canvas drawing buffer size
384
404
  if (this.props.autoResize) {
@@ -390,9 +410,6 @@ export abstract class CanvasContext {
390
410
  } else {
391
411
  this.setDrawingBufferSize(this.cssWidth, this.cssHeight);
392
412
  }
393
-
394
- // Inform the subclass
395
- this._updateDevice();
396
413
  }
397
414
 
398
415
  // Resolve the initialized promise
@@ -402,6 +419,23 @@ export abstract class CanvasContext {
402
419
  this.updatePosition();
403
420
  }
404
421
 
422
+ /** Perform a deferred resize of the drawing buffer if needed */
423
+ _resizeDrawingBufferIfNeeded() {
424
+ if (this._needsDrawingBufferResize) {
425
+ this._needsDrawingBufferResize = false;
426
+ const sizeChanged =
427
+ this.drawingBufferWidth !== this.canvas.width ||
428
+ this.drawingBufferHeight !== this.canvas.height;
429
+ if (sizeChanged) {
430
+ // Update the canvas size
431
+ this.canvas.width = this.drawingBufferWidth;
432
+ this.canvas.height = this.drawingBufferHeight;
433
+ // Inform the subclass: WebGPU needs to call canvascontext.configure()
434
+ this._configureDevice();
435
+ }
436
+ }
437
+ }
438
+
405
439
  /** Monitor DPR changes */
406
440
  _observeDevicePixelRatio() {
407
441
  const oldRatio = this.devicePixelRatio;
@@ -24,6 +24,7 @@ import type {CommandBuffer} from './resources/command-buffer';
24
24
  import type {VertexArray, VertexArrayProps} from './resources/vertex-array';
25
25
  import type {TransformFeedback, TransformFeedbackProps} from './resources/transform-feedback';
26
26
  import type {QuerySet, QuerySetProps} from './resources/query-set';
27
+ import type {Fence} from './resources/fence';
27
28
 
28
29
  import {getVertexFormatInfo} from '../shadertypes/vertex-arrays/decode-vertex-format';
29
30
  import {textureFormatDecoder} from '../shadertypes/textures/texture-format-decoder';
@@ -400,7 +401,7 @@ export abstract class Device {
400
401
  /** True if this device has been reused during device creation (app has multiple references) */
401
402
  _reused: boolean = false;
402
403
  /** Used by other luma.gl modules to store data on the device */
403
- _lumaData: {[key: string]: unknown} = {};
404
+ private _moduleData: Record<string, Record<string, unknown>> = {};
404
405
 
405
406
  // Capabilities
406
407
 
@@ -451,9 +452,6 @@ export abstract class Device {
451
452
  return textureCaps;
452
453
  }
453
454
 
454
- /** Return the implementation specific alignment for a texture format. 1 on WebGL, 256 on WebGPU */
455
- abstract getTextureByteAlignment(): number;
456
-
457
455
  /** Calculates the number of mip levels for a texture of width, height and in case of 3d textures only, depth */
458
456
  getMipLevelCount(width: number, height: number, depth3d: number = 1): number {
459
457
  const maxSize = Math.max(width, height, depth3d);
@@ -548,7 +546,13 @@ export abstract class Device {
548
546
  const isHandled = this.props.onError(error, context);
549
547
  if (!isHandled) {
550
548
  // Note: Returns a function that must be called: `device.reportError(...)()`
551
- return log.error(error.message, context, ...args);
549
+ return log.error(
550
+ this.type === 'webgl' ? '%cWebGL' : '%cWebGPU',
551
+ 'color: white; background: red; padding: 2px 6px; border-radius: 3px;',
552
+ error.message,
553
+ context,
554
+ ...args
555
+ );
552
556
  }
553
557
  return () => {};
554
558
  }
@@ -622,6 +626,11 @@ or create a device with the 'debug: true' prop.`;
622
626
 
623
627
  abstract createQuerySet(props: QuerySetProps): QuerySet;
624
628
 
629
+ /** Create a fence sync object */
630
+ createFence(): Fence {
631
+ throw new Error('createFence() not implemented');
632
+ }
633
+
625
634
  /** Create a RenderPass using the default CommandEncoder */
626
635
  beginRenderPass(props?: RenderPassProps): RenderPass {
627
636
  return this.commandEncoder.beginRenderPass(props);
@@ -711,6 +720,15 @@ or create a device with the 'debug: true' prop.`;
711
720
  throw new Error('not implemented');
712
721
  }
713
722
 
723
+ // INTERNAL LUMA.GL METHODS
724
+
725
+ getModuleData<ModuleDataT extends Record<string, unknown>>(moduleName: string): ModuleDataT {
726
+ this._moduleData[moduleName] ||= {};
727
+ return this._moduleData[moduleName] as ModuleDataT;
728
+ }
729
+
730
+ // INTERNAL HELPERS
731
+
714
732
  // IMPLEMENTATION
715
733
 
716
734
  /** Helper to get the canvas context props */
@@ -756,6 +774,10 @@ or create a device with the 'debug: true' prop.`;
756
774
  newProps.indexType = 'uint32';
757
775
  } else if (props.data instanceof Uint16Array) {
758
776
  newProps.indexType = 'uint16';
777
+ } else if (props.data instanceof Uint8Array) {
778
+ // Convert uint8 to uint16 for WebGPU compatibility (WebGPU doesn't support uint8 indices)
779
+ newProps.data = new Uint16Array(props.data);
780
+ newProps.indexType = 'uint16';
759
781
  }
760
782
  }
761
783
  if (!newProps.indexType) {
@@ -17,8 +17,8 @@ export type BufferProps = ResourceProps & {
17
17
  byteLength?: number;
18
18
  /** Byte offset into the newly created Buffer to store data at */
19
19
  byteOffset?: number;
20
- /** If props.usage includes Buffer.INDEX */
21
- indexType?: 'uint16' | 'uint32';
20
+ /** If props.usage includes Buffer.INDEX. Note: uint8 indices are automatically converted to uint16 for WebGPU compatibility */
21
+ indexType?: 'uint8' | 'uint16' | 'uint32';
22
22
  /** Data to initialize the buffer with. */
23
23
  data?: ArrayBuffer | ArrayBufferView | null;
24
24
  /** Callback to initialize data without copy */
@@ -50,8 +50,8 @@ export abstract class Buffer extends Resource<BufferProps> {
50
50
 
51
51
  /** The usage with which this buffer was created */
52
52
  readonly usage: number;
53
- /** For index buffers, whether indices are 16 or 32 bit */
54
- readonly indexType?: 'uint16' | 'uint32';
53
+ /** For index buffers, whether indices are 8, 16 or 32 bit. Note: uint8 indices are automatically converted to uint16 for WebGPU compatibility */
54
+ readonly indexType?: 'uint8' | 'uint16' | 'uint32';
55
55
  /** Length of buffer in bytes */
56
56
  abstract byteLength: number;
57
57
  /** "Time" of last update, can be used to check if redraw is needed */
@@ -66,6 +66,8 @@ export abstract class Buffer extends Resource<BufferProps> {
66
66
  deducedProps.indexType = 'uint32';
67
67
  } else if (props.data instanceof Uint16Array) {
68
68
  deducedProps.indexType = 'uint16';
69
+ } else if (props.data instanceof Uint8Array) {
70
+ deducedProps.indexType = 'uint8';
69
71
  }
70
72
  }
71
73
 
@@ -11,7 +11,7 @@ import {Resource, ResourceProps} from './resource';
11
11
  // // onSubmittedWorkDone(): Promise<undefined>;
12
12
 
13
13
  // writeBuffer(options: WriteBufferOptions): void;
14
- // writeTexture(options: WriteTextureOptions): void;
14
+ // writeTexture(options: TextureWriteOptions): void;
15
15
 
16
16
  // // copyExternalImageToTexture(
17
17
  // // GPUImageCopyExternalImage source,
@@ -113,7 +113,7 @@ export type ClearTextureOptions = {
113
113
  // size?: number;
114
114
  // };
115
115
 
116
- // export type WriteTextureOptions = {
116
+ // export type TextureWriteOptions = {
117
117
  // destination: Texture;
118
118
  // mipLevel?: number; // = 0;
119
119
  // origin?: [number, number, number] | number[];
@@ -166,7 +166,7 @@ export abstract class CommandEncoder extends Resource<CommandEncoderProps> {
166
166
  /** Add a command that clears a texture mip level. */
167
167
  // abstract clearTexture(options: ClearTextureOptions): void;
168
168
 
169
- // abstract readTexture(options: ReadTextureOptions): Promise<TypedArray>;
169
+ // abstract readTexture(options: TextureReadOptions): Promise<TypedArray>;
170
170
 
171
171
  /** Reads results from a query set into a GPU buffer. Values are 64 bits so byteLength must be querySet.props.count * 8 */
172
172
  abstract resolveQuerySet(
@@ -0,0 +1,30 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Device} from '../device';
6
+ import {Resource, type ResourceProps} from './resource';
7
+
8
+ export type FenceProps = ResourceProps;
9
+
10
+ /** Synchronization primitive that resolves when GPU work is completed */
11
+ export abstract class Fence extends Resource<FenceProps> {
12
+ static override defaultProps: Required<FenceProps> = {
13
+ ...Resource.defaultProps
14
+ };
15
+
16
+ [Symbol.toStringTag]: string = 'WEBGLFence';
17
+
18
+ /** Promise that resolves when the fence is signaled */
19
+ abstract readonly signaled: Promise<void>;
20
+
21
+ constructor(device: Device, props: FenceProps = {}) {
22
+ super(device, props, Fence.defaultProps);
23
+ }
24
+
25
+ /** Destroy the fence and release any resources */
26
+ abstract override destroy(): void;
27
+
28
+ /** Check if the fence has been signaled */
29
+ abstract isSignaled(): boolean;
30
+ }
@@ -56,7 +56,12 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
56
56
  const depthStencilAttachment =
57
57
  this.depthStencilAttachment && this.depthStencilAttachment.texture.clone(size);
58
58
 
59
- return this.device.createFramebuffer({...this.props, colorAttachments, depthStencilAttachment});
59
+ return this.device.createFramebuffer({
60
+ ...this.props,
61
+ ...size,
62
+ colorAttachments,
63
+ depthStencilAttachment
64
+ });
60
65
  }
61
66
 
62
67
  /**
@@ -33,10 +33,15 @@ export abstract class Resource<Props extends ResourceProps> {
33
33
 
34
34
  /** props.id, for debugging. */
35
35
  id: string;
36
+ /** The props that this resource was created with */
36
37
  readonly props: Required<Props>;
38
+ /** User data object, reserved for the application */
37
39
  readonly userData: Record<string, unknown> = {};
40
+ /** The device that this resource is associated with */
38
41
  abstract readonly device: Device;
42
+ /** The handle for the underlying resource, e.g. WebGL object or WebGPU handle */
39
43
  abstract readonly handle: unknown;
44
+ /** The device that this resource is associated with - TODO can we remove this dup? */
40
45
  private _device: Device;
41
46
 
42
47
  /** Whether this resource has been destroyed */