@luma.gl/test-utils 9.3.0-alpha.6 → 9.3.0-alpha.9

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 (43) hide show
  1. package/dist/create-test-device.d.ts +19 -0
  2. package/dist/create-test-device.d.ts.map +1 -1
  3. package/dist/create-test-device.js +83 -14
  4. package/dist/create-test-device.js.map +1 -1
  5. package/dist/deprecated/sync-test-device.d.ts +0 -5
  6. package/dist/deprecated/sync-test-device.d.ts.map +1 -1
  7. package/dist/deprecated/sync-test-device.js +11 -1
  8. package/dist/deprecated/sync-test-device.js.map +1 -1
  9. package/dist/index.cjs +145 -53
  10. package/dist/index.cjs.map +4 -4
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/null-device/null-device.d.ts +1 -1
  16. package/dist/null-device/null-device.d.ts.map +1 -1
  17. package/dist/null-device/null-device.js +2 -2
  18. package/dist/null-device/null-device.js.map +1 -1
  19. package/dist/null-device/resources/null-command-buffer.d.ts +6 -6
  20. package/dist/null-device/resources/null-command-buffer.d.ts.map +1 -1
  21. package/dist/null-device/resources/null-command-buffer.js +16 -6
  22. package/dist/null-device/resources/null-command-buffer.js.map +1 -1
  23. package/dist/null-device/resources/null-command-encoder.d.ts +6 -6
  24. package/dist/null-device/resources/null-command-encoder.d.ts.map +1 -1
  25. package/dist/null-device/resources/null-command-encoder.js +18 -8
  26. package/dist/null-device/resources/null-command-encoder.js.map +1 -1
  27. package/dist/null-device/resources/null-texture.d.ts +2 -2
  28. package/dist/null-device/resources/null-texture.d.ts.map +1 -1
  29. package/dist/null-device/resources/null-texture.js +7 -4
  30. package/dist/null-device/resources/null-texture.js.map +1 -1
  31. package/dist/test-runner.d.ts +1 -1
  32. package/dist/test-runner.d.ts.map +1 -1
  33. package/dist/test-runner.js +2 -1
  34. package/dist/test-runner.js.map +1 -1
  35. package/package.json +7 -7
  36. package/src/create-test-device.ts +113 -14
  37. package/src/deprecated/sync-test-device.ts +16 -1
  38. package/src/index.ts +1 -0
  39. package/src/null-device/null-device.ts +2 -2
  40. package/src/null-device/resources/null-command-buffer.ts +16 -6
  41. package/src/null-device/resources/null-command-encoder.ts +17 -7
  42. package/src/null-device/resources/null-texture.ts +9 -4
  43. package/src/test-runner.ts +2 -1
@@ -2,6 +2,22 @@ import type { Device } from '@luma.gl/core';
2
2
  import { WebGLDevice } from '@luma.gl/webgl';
3
3
  import { WebGPUDevice } from '@luma.gl/webgpu';
4
4
  import { NullDevice } from "./null-device/null-device.js";
5
+ declare const TEST_DEVICE_CACHE_KEY = "__lumaTestDeviceCache";
6
+ type TestDeviceCache = {
7
+ /** A null device intended for testing - @note Only available after getTestDevices() has completed */
8
+ nullDevicePromise: Promise<NullDevice> | null;
9
+ /** This WebGL Device can be used directly but will not have WebGL debugging initialized */
10
+ webglDevicePromise: Promise<WebGLDevice> | null;
11
+ /** A shared offscreen WebGL device for presentation-context tests */
12
+ presentationWebglDevicePromise: Promise<WebGLDevice | null> | null;
13
+ /** A WebGL 2 Device intended for testing - @note Only available after getTestDevices() has completed */
14
+ webgpuDevicePromise: Promise<WebGPUDevice | null> | null;
15
+ };
16
+ declare global {
17
+ interface Window {
18
+ [TEST_DEVICE_CACHE_KEY]?: TestDeviceCache;
19
+ }
20
+ }
5
21
  /** Includes WebGPU device if available */
6
22
  export declare function getTestDevices(types?: Readonly<('webgl' | 'webgpu' | 'null' | 'unknown')[]>): Promise<Device[]>;
7
23
  export declare function getTestDevice(type: 'webgl' | 'webgpu' | 'null' | 'unknown'): Promise<Device | null>;
@@ -9,6 +25,9 @@ export declare function getTestDevice(type: 'webgl' | 'webgpu' | 'null' | 'unkno
9
25
  export declare function getWebGPUTestDevice(): Promise<WebGPUDevice | null>;
10
26
  /** returns WebGL device promise, if available */
11
27
  export declare function getWebGLTestDevice(): Promise<WebGLDevice>;
28
+ /** returns an offscreen WebGL device promise for presentation-context tests, if available */
29
+ export declare function getPresentationWebGLTestDevice(): Promise<WebGLDevice | null>;
12
30
  /** returns null device promise, if available */
13
31
  export declare function getNullTestDevice(): Promise<NullDevice>;
32
+ export {};
14
33
  //# sourceMappingURL=create-test-device.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-test-device.d.ts","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAqB,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAgB,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAgB,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAC,UAAU,EAAC,qCAAkC;AAWrD,0CAA0C;AAC1C,wBAAsB,cAAc,CAClC,KAAK,GAAE,QAAQ,CAAC,CAAC,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,CAAuB,GACjF,OAAO,CAAC,MAAM,EAAE,CAAC,CAInB;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAC5C,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAED,kDAAkD;AAClD,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAElE;AAED,iDAAiD;AACjD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,WAAW,CAAC,CAE/D;AAED,gDAAgD;AAChD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,UAAU,CAAC,CAE7D"}
1
+ {"version":3,"file":"create-test-device.d.ts","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAqB,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAgB,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAgB,YAAY,EAAC,MAAM,iBAAiB,CA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.gl/webgl';
6
6
  import { webgpuAdapter } from '@luma.gl/webgpu';
7
7
  import { nullAdapter } from "./null-device/null-adapter.js";
8
8
  const DEFAULT_CANVAS_CONTEXT_PROPS = { width: 1, height: 1 };
9
- /** A null device intended for testing - @note Only available after getTestDevices() has completed */
10
- let nullDevicePromise = makeNullTestDevice();
11
- /** This WebGL Device can be used directly but will not have WebGL debugging initialized */
12
- const webglDevicePromise = makeWebGLTestDevice();
13
- /** A WebGL 2 Device intended for testing - @note Only available after getTestDevices() has completed */
14
- const webgpuDevicePromise = makeWebGPUTestDevice();
9
+ const TEST_DEVICE_CACHE_KEY = '__lumaTestDeviceCache';
10
+ const testDeviceCache = getOrCreateTestDeviceCache();
15
11
  /** Includes WebGPU device if available */
16
12
  export async function getTestDevices(types = ['webgl', 'webgpu']) {
17
13
  const promises = types.map(type => getTestDevice(type));
@@ -21,26 +17,53 @@ export async function getTestDevices(types = ['webgl', 'webgpu']) {
21
17
  export async function getTestDevice(type) {
22
18
  switch (type) {
23
19
  case 'webgl':
24
- return webglDevicePromise;
20
+ return getOrCreateWebGLTestDevicePromise();
25
21
  case 'webgpu':
26
- return webgpuDevicePromise;
22
+ return getWebGPUTestDevice();
27
23
  case 'null':
28
- return nullDevicePromise;
24
+ return getOrCreateNullTestDevicePromise();
29
25
  case 'unknown':
30
26
  return null;
31
27
  }
32
28
  }
33
29
  /** returns WebGPU device promise, if available */
34
- export function getWebGPUTestDevice() {
35
- return webgpuDevicePromise;
30
+ export async function getWebGPUTestDevice() {
31
+ const webgpuDevice = await getOrCreateWebGPUTestDevicePromise();
32
+ if (webgpuDevice?.isLost) {
33
+ if (testDeviceCache.webgpuDevicePromise) {
34
+ testDeviceCache.webgpuDevicePromise = null;
35
+ }
36
+ return getOrCreateWebGPUTestDevicePromise();
37
+ }
38
+ return webgpuDevice;
36
39
  }
37
40
  /** returns WebGL device promise, if available */
38
41
  export async function getWebGLTestDevice() {
39
- return webglDevicePromise;
42
+ return getOrCreateWebGLTestDevicePromise();
43
+ }
44
+ /** returns an offscreen WebGL device promise for presentation-context tests, if available */
45
+ export async function getPresentationWebGLTestDevice() {
46
+ return getOrCreatePresentationWebGLTestDevicePromise();
40
47
  }
41
48
  /** returns null device promise, if available */
42
49
  export async function getNullTestDevice() {
43
- return nullDevicePromise;
50
+ return getOrCreateNullTestDevicePromise();
51
+ }
52
+ function getOrCreateWebGPUTestDevicePromise() {
53
+ testDeviceCache.webgpuDevicePromise ||= makeWebGPUTestDevice();
54
+ return testDeviceCache.webgpuDevicePromise;
55
+ }
56
+ function getOrCreateWebGLTestDevicePromise() {
57
+ testDeviceCache.webglDevicePromise ||= makeWebGLTestDevice();
58
+ return testDeviceCache.webglDevicePromise;
59
+ }
60
+ function getOrCreatePresentationWebGLTestDevicePromise() {
61
+ testDeviceCache.presentationWebglDevicePromise ||= makePresentationWebGLTestDevice();
62
+ return testDeviceCache.presentationWebglDevicePromise;
63
+ }
64
+ function getOrCreateNullTestDevicePromise() {
65
+ testDeviceCache.nullDevicePromise ||= makeNullTestDevice();
66
+ return testDeviceCache.nullDevicePromise;
44
67
  }
45
68
  async function makeWebGPUTestDevice() {
46
69
  const webgpuDeviceResolvers = withResolvers();
@@ -52,6 +75,11 @@ async function makeWebGPUTestDevice() {
52
75
  createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS,
53
76
  debug: true
54
77
  }));
78
+ webgpuDevice.lost.finally(() => {
79
+ if (testDeviceCache.webgpuDevicePromise === webgpuDeviceResolvers.promise) {
80
+ testDeviceCache.webgpuDevicePromise = null;
81
+ }
82
+ });
55
83
  webgpuDeviceResolvers.resolve(webgpuDevice);
56
84
  }
57
85
  catch (error) {
@@ -72,6 +100,11 @@ async function makeWebGLTestDevice() {
72
100
  createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS,
73
101
  debug: true
74
102
  }));
103
+ webglDevice.lost.finally(() => {
104
+ if (testDeviceCache.webglDevicePromise === webglDeviceResolvers.promise) {
105
+ testDeviceCache.webglDevicePromise = null;
106
+ }
107
+ });
75
108
  webglDeviceResolvers.resolve(webglDevice);
76
109
  }
77
110
  catch (error) {
@@ -81,6 +114,32 @@ async function makeWebGLTestDevice() {
81
114
  }
82
115
  return webglDeviceResolvers.promise;
83
116
  }
117
+ async function makePresentationWebGLTestDevice() {
118
+ if (typeof OffscreenCanvas === 'undefined') {
119
+ return null;
120
+ }
121
+ const presentationWebGLDeviceResolvers = withResolvers();
122
+ try {
123
+ const webglDevice = (await luma.createDevice({
124
+ id: 'webgl-presentation-context-test-device',
125
+ type: 'webgl',
126
+ adapters: [webgl2Adapter],
127
+ createCanvasContext: { canvas: new OffscreenCanvas(4, 4) },
128
+ debug: true
129
+ }));
130
+ webglDevice.lost.finally(() => {
131
+ if (testDeviceCache.presentationWebglDevicePromise === presentationWebGLDeviceResolvers.promise) {
132
+ testDeviceCache.presentationWebglDevicePromise = null;
133
+ }
134
+ });
135
+ presentationWebGLDeviceResolvers.resolve(webglDevice);
136
+ }
137
+ catch (error) {
138
+ log.error(String(error))();
139
+ presentationWebGLDeviceResolvers.resolve(null);
140
+ }
141
+ return presentationWebGLDeviceResolvers.promise;
142
+ }
84
143
  /** returns null device promise, if available */
85
144
  async function makeNullTestDevice() {
86
145
  const nullDeviceResolvers = withResolvers();
@@ -97,11 +156,21 @@ async function makeNullTestDevice() {
97
156
  catch (error) {
98
157
  log.error(String(error))();
99
158
  // @ts-ignore TODO
100
- nullDevicePromise = Promise.resolve(null);
159
+ testDeviceCache.nullDevicePromise = Promise.resolve(null);
101
160
  }
102
161
  return nullDeviceResolvers.promise;
103
162
  }
104
163
  // HELPERS
164
+ function getOrCreateTestDeviceCache() {
165
+ const rootObject = globalThis;
166
+ rootObject[TEST_DEVICE_CACHE_KEY] ||= {
167
+ nullDevicePromise: null,
168
+ webglDevicePromise: null,
169
+ presentationWebglDevicePromise: null,
170
+ webgpuDevicePromise: null
171
+ };
172
+ return rootObject[TEST_DEVICE_CACHE_KEY];
173
+ }
105
174
  // TODO - replace with Promise.withResolvers once we upgrade TS baseline
106
175
  function withResolvers() {
107
176
  let resolve;
@@ -1 +1 @@
1
- {"version":3,"file":"create-test-device.js","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,IAAI,EAAE,GAAG,EAAC,MAAM,eAAe,CAAC;AACxC,OAAO,EAAC,aAAa,EAAc,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAe,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAC,sCAAmC;AAGvD,MAAM,4BAA4B,GAAuB,EAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAC,CAAC;AAE/E,qGAAqG;AACrG,IAAI,iBAAiB,GAAG,kBAAkB,EAAE,CAAC;AAC7C,2FAA2F;AAC3F,MAAM,kBAAkB,GAAG,mBAAmB,EAAE,CAAC;AACjD,wGAAwG;AACxG,MAAM,mBAAmB,GAAG,oBAAoB,EAAE,CAAC;AAEnD,0CAA0C;AAC1C,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAA+D,CAAC,OAAO,EAAE,QAAQ,CAAC;IAElF,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAA6C;IAE7C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,kBAAkB,CAAC;QAC5B,KAAK,QAAQ;YACX,OAAO,mBAAmB,CAAC;QAC7B,KAAK,MAAM;Y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AmC;IACnC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAC,CAAC;AACpC,CAAC"}
@@ -5,10 +5,5 @@ import { WebGLDevice } from '@luma.gl/webgl';
5
5
  * @deprecated Use getWebGLTestDevice().
6
6
  */
7
7
  export declare function createTestDevice(): WebGLDevice | null;
8
- /**
9
- * A pre-created WebGLDevice
10
- * @note This WebGL Device is create synchronously and can be used directly but will not have WebGL debugging initialized
11
- * @deprecated Use getWebGLTestDevice().
12
- */
13
8
  export declare const webglDevice: WebGLDevice | null;
14
9
  //# sourceMappingURL=sync-test-device.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-test-device.d.ts","sourceRoot":"","sources":["../../src/deprecated/sync-test-device.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAO3C;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,GAAG,IAAI,CAUrD;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,oBAAqB,CAAC"}
1
+ {"version":3,"file":"sync-test-device.d.ts","sourceRoot":"","sources":["../../src/deprecated/sync-test-device.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAO3C;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,GAAG,IAAI,CAuBrD;AASD,eAAO,MAAM,WAAW,oBAAqB,CAAC"}
@@ -12,9 +12,18 @@ const DEFAULT_CANVAS_CONTEXT_PROPS = {
12
12
  * @deprecated Use getWebGLTestDevice().
13
13
  */
14
14
  export function createTestDevice() {
15
+ if (cachedWebglDevice) {
16
+ return cachedWebglDevice;
17
+ }
18
+ if (typeof navigator === 'undefined' ||
19
+ typeof document === 'undefined' ||
20
+ typeof HTMLCanvasElement === 'undefined') {
21
+ return null;
22
+ }
15
23
  try {
16
24
  // TODO - We do not use luma.createDevice since createTestDevice currently expect WebGL context to be created synchronously
17
- return new WebGLDevice({ createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS });
25
+ cachedWebglDevice = new WebGLDevice({ createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS });
26
+ return cachedWebglDevice;
18
27
  }
19
28
  catch (error) {
20
29
  // eslint-disable-next-line no-console
@@ -28,5 +37,6 @@ export function createTestDevice() {
28
37
  * @note This WebGL Device is create synchronously and can be used directly but will not have WebGL debugging initialized
29
38
  * @deprecated Use getWebGLTestDevice().
30
39
  */
40
+ let cachedWebglDevice = null;
31
41
  export const webglDevice = createTestDevice();
32
42
  //# sourceMappingURL=sync-test-device.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-test-device.js","sourceRoot":"","sources":["../../src/deprecated/sync-test-device.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,eAAe;AACf,oCAAoC;AAGpC,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE3C,MAAM,4BAA4B,GAAuB;IACvD,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC;QACH,2HAA2H;QAC3H,OAAO,IAAI,WAAW,CAAC,EAAC,mBAAmB,EAAE,4BAA4B,EAAC,CAAC,CAAC;IAC9E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,6BAA8B,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,QAAQ,CAAC,CAAC,kCAAkC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"sync-test-device.js","sourceRoot":"","sources":["../../src/deprecated/sync-test-device.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,eAAe;AACf,oCAAoC;AAGpC,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE3C,MAAM,4BAA4B,GAAuB;IACvD,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,IACE,OAAO,SAAS,KAAK,WAAW;QAChC,OAAO,QAAQ,KAAK,WAAW;QAC/B,OAAO,iBAAiB,KAAK,WAAW,EACxC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,2HAA2H;QAC3H,iBAAiB,GAAG,IAAI,WAAW,CAAC,EAAC,mBAAmB,EAAE,4BAA4B,EAAC,CAAC,CAAC;QACzF,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,6BAA8B,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,QAAQ,CAAC,CAAC,kCAAkC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,IAAI,iBAAiB,GAAuB,IAAI,CAAC;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,EAAE,CAAC"}
package/dist/index.cjs CHANGED
@@ -29,13 +29,14 @@ __export(dist_exports, {
29
29
  deepCopy: () => deepCopy,
30
30
  getLeakedResources: () => getLeakedResources,
31
31
  getNullTestDevice: () => getNullTestDevice,
32
+ getPresentationWebGLTestDevice: () => getPresentationWebGLTestDevice,
32
33
  getResourceCounts: () => getResourceCounts,
33
34
  getTestDevice: () => getTestDevice,
34
35
  getTestDevices: () => getTestDevices,
35
36
  getWebGLTestDevice: () => getWebGLTestDevice,
36
37
  getWebGPUTestDevice: () => getWebGPUTestDevice,
37
38
  nullAdapter: () => nullAdapter,
38
- webglDevice: () => webglDevice2
39
+ webglDevice: () => webglDevice
39
40
  });
40
41
  module.exports = __toCommonJS(dist_exports);
41
42
 
@@ -232,21 +233,26 @@ var NullCommandBuffer = class extends import_core7.CommandBuffer {
232
233
  super(device, props);
233
234
  this.device = device;
234
235
  }
235
- copyBufferToBuffer(options) {
236
+ copyBufferToBuffer(_options) {
237
+ throw new Error("copyBufferToBuffer is not supported on NullDevice");
236
238
  }
237
- copyBufferToTexture(options) {
239
+ copyBufferToTexture(_options) {
240
+ throw new Error("copyBufferToTexture is not supported on NullDevice");
238
241
  }
239
- copyTextureToBuffer(options) {
242
+ copyTextureToBuffer(_options) {
243
+ throw new Error("copyTextureToBuffer is not supported on NullDevice");
240
244
  }
241
- copyTextureToTexture(options) {
245
+ copyTextureToTexture(_options) {
246
+ throw new Error("copyTextureToTexture is not supported on NullDevice");
242
247
  }
243
248
  pushDebugGroup(groupLabel) {
244
249
  }
245
250
  popDebugGroup() {
246
251
  }
247
- insertDebugMarker(markerLabel) {
252
+ insertDebugMarker(_markerLabel) {
248
253
  }
249
- resolveQuerySet(querySet) {
254
+ resolveQuerySet(_querySet) {
255
+ throw new Error("resolveQuerySet is not supported on NullDevice");
250
256
  }
251
257
  };
252
258
 
@@ -298,18 +304,23 @@ var NullCommandEncoder = class extends import_core9.CommandEncoder {
298
304
  beginRenderPass(props) {
299
305
  return new NullRenderPass(this.device, props);
300
306
  }
301
- beginComputePass(props) {
302
- throw new Error("ComputePass not supported in WebGL");
307
+ beginComputePass(_props) {
308
+ throw new Error("ComputePass is not supported on NullDevice");
303
309
  }
304
- copyBufferToBuffer(options) {
310
+ copyBufferToBuffer(_options) {
311
+ throw new Error("copyBufferToBuffer is not supported on NullDevice");
305
312
  }
306
- copyBufferToTexture(options) {
313
+ copyBufferToTexture(_options) {
314
+ throw new Error("copyBufferToTexture is not supported on NullDevice");
307
315
  }
308
- copyTextureToBuffer(options) {
316
+ copyTextureToBuffer(_options) {
317
+ throw new Error("copyTextureToBuffer is not supported on NullDevice");
309
318
  }
310
- copyTextureToTexture(options) {
319
+ copyTextureToTexture(_options) {
320
+ throw new Error("copyTextureToTexture is not supported on NullDevice");
311
321
  }
312
- resolveQuerySet(querySet) {
322
+ resolveQuerySet(_querySet) {
323
+ throw new Error("resolveQuerySet is not supported on NullDevice");
313
324
  }
314
325
  pushDebugGroup(groupLabel) {
315
326
  }
@@ -385,11 +396,14 @@ var NullTexture = class extends import_core12.Texture {
385
396
  copyImageData(options) {
386
397
  super.copyImageData(options);
387
398
  }
388
- readBuffer(options = {}, buffer) {
389
- return this.device.createBuffer({});
399
+ readBuffer(_options = {}, buffer) {
400
+ if (!buffer) {
401
+ throw new Error("buffer required");
402
+ }
403
+ return buffer;
390
404
  }
391
- async readDataAsync(options = {}) {
392
- return new ArrayBuffer(0);
405
+ async readDataAsync(_options = {}) {
406
+ throw new Error(`${this} readDataAsync is deprecated; use readBuffer() with an explicit destination buffer or DynamicTexture.readAsync()`);
393
407
  }
394
408
  writeBuffer(buffer, options = {}) {
395
409
  }
@@ -603,8 +617,8 @@ var NullDevice = class extends import_core18.Device {
603
617
  createRenderPipeline(props) {
604
618
  return new NullRenderPipeline(this, props);
605
619
  }
606
- createComputePipeline(props) {
607
- throw new Error("ComputePipeline not supported in WebGL");
620
+ createComputePipeline(_props) {
621
+ throw new Error("ComputePipeline is not supported on NullDevice");
608
622
  }
609
623
  createCommandEncoder(props = {}) {
610
624
  return new NullCommandEncoder(this, props);
@@ -663,9 +677,8 @@ var nullAdapter = new NullAdapter();
663
677
 
664
678
  // dist/create-test-device.js
665
679
  var DEFAULT_CANVAS_CONTEXT_PROPS = { width: 1, height: 1 };
666
- var nullDevicePromise = makeNullTestDevice();
667
- var webglDevicePromise = makeWebGLTestDevice();
668
- var webgpuDevicePromise = makeWebGPUTestDevice();
680
+ var TEST_DEVICE_CACHE_KEY = "__lumaTestDeviceCache";
681
+ var testDeviceCache = getOrCreateTestDeviceCache();
669
682
  async function getTestDevices(types = ["webgl", "webgpu"]) {
670
683
  const promises = types.map((type) => getTestDevice(type));
671
684
  const devices = await Promise.all(promises);
@@ -674,23 +687,49 @@ async function getTestDevices(types = ["webgl", "webgpu"]) {
674
687
  async function getTestDevice(type) {
675
688
  switch (type) {
676
689
  case "webgl":
677
- return webglDevicePromise;
690
+ return getOrCreateWebGLTestDevicePromise();
678
691
  case "webgpu":
679
- return webgpuDevicePromise;
692
+ return getWebGPUTestDevice();
680
693
  case "null":
681
- return nullDevicePromise;
694
+ return getOrCreateNullTestDevicePromise();
682
695
  case "unknown":
683
696
  return null;
684
697
  }
685
698
  }
686
- function getWebGPUTestDevice() {
687
- return webgpuDevicePromise;
699
+ async function getWebGPUTestDevice() {
700
+ const webgpuDevice = await getOrCreateWebGPUTestDevicePromise();
701
+ if (webgpuDevice == null ? void 0 : webgpuDevice.isLost) {
702
+ if (testDeviceCache.webgpuDevicePromise) {
703
+ testDeviceCache.webgpuDevicePromise = null;
704
+ }
705
+ return getOrCreateWebGPUTestDevicePromise();
706
+ }
707
+ return webgpuDevice;
688
708
  }
689
709
  async function getWebGLTestDevice() {
690
- return webglDevicePromise;
710
+ return getOrCreateWebGLTestDevicePromise();
711
+ }
712
+ async function getPresentationWebGLTestDevice() {
713
+ return getOrCreatePresentationWebGLTestDevicePromise();
691
714
  }
692
715
  async function getNullTestDevice() {
693
- return nullDevicePromise;
716
+ return getOrCreateNullTestDevicePromise();
717
+ }
718
+ function getOrCreateWebGPUTestDevicePromise() {
719
+ testDeviceCache.webgpuDevicePromise ||= makeWebGPUTestDevice();
720
+ return testDeviceCache.webgpuDevicePromise;
721
+ }
722
+ function getOrCreateWebGLTestDevicePromise() {
723
+ testDeviceCache.webglDevicePromise ||= makeWebGLTestDevice();
724
+ return testDeviceCache.webglDevicePromise;
725
+ }
726
+ function getOrCreatePresentationWebGLTestDevicePromise() {
727
+ testDeviceCache.presentationWebglDevicePromise ||= makePresentationWebGLTestDevice();
728
+ return testDeviceCache.presentationWebglDevicePromise;
729
+ }
730
+ function getOrCreateNullTestDevicePromise() {
731
+ testDeviceCache.nullDevicePromise ||= makeNullTestDevice();
732
+ return testDeviceCache.nullDevicePromise;
694
733
  }
695
734
  async function makeWebGPUTestDevice() {
696
735
  const webgpuDeviceResolvers = withResolvers();
@@ -702,6 +741,11 @@ async function makeWebGPUTestDevice() {
702
741
  createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS,
703
742
  debug: true
704
743
  });
744
+ webgpuDevice.lost.finally(() => {
745
+ if (testDeviceCache.webgpuDevicePromise === webgpuDeviceResolvers.promise) {
746
+ testDeviceCache.webgpuDevicePromise = null;
747
+ }
748
+ });
705
749
  webgpuDeviceResolvers.resolve(webgpuDevice);
706
750
  } catch (error) {
707
751
  import_core20.log.error(String(error))();
@@ -712,20 +756,50 @@ async function makeWebGPUTestDevice() {
712
756
  async function makeWebGLTestDevice() {
713
757
  const webglDeviceResolvers = withResolvers();
714
758
  try {
715
- const webglDevice3 = await import_core20.luma.createDevice({
759
+ const webglDevice2 = await import_core20.luma.createDevice({
716
760
  id: "webgl-test-device",
717
761
  type: "webgl",
718
762
  adapters: [import_webgl2.webgl2Adapter],
719
763
  createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS,
720
764
  debug: true
721
765
  });
722
- webglDeviceResolvers.resolve(webglDevice3);
766
+ webglDevice2.lost.finally(() => {
767
+ if (testDeviceCache.webglDevicePromise === webglDeviceResolvers.promise) {
768
+ testDeviceCache.webglDevicePromise = null;
769
+ }
770
+ });
771
+ webglDeviceResolvers.resolve(webglDevice2);
723
772
  } catch (error) {
724
773
  import_core20.log.error(String(error))();
725
774
  webglDeviceResolvers.resolve(null);
726
775
  }
727
776
  return webglDeviceResolvers.promise;
728
777
  }
778
+ async function makePresentationWebGLTestDevice() {
779
+ if (typeof OffscreenCanvas === "undefined") {
780
+ return null;
781
+ }
782
+ const presentationWebGLDeviceResolvers = withResolvers();
783
+ try {
784
+ const webglDevice2 = await import_core20.luma.createDevice({
785
+ id: "webgl-presentation-context-test-device",
786
+ type: "webgl",
787
+ adapters: [import_webgl2.webgl2Adapter],
788
+ createCanvasContext: { canvas: new OffscreenCanvas(4, 4) },
789
+ debug: true
790
+ });
791
+ webglDevice2.lost.finally(() => {
792
+ if (testDeviceCache.presentationWebglDevicePromise === presentationWebGLDeviceResolvers.promise) {
793
+ testDeviceCache.presentationWebglDevicePromise = null;
794
+ }
795
+ });
796
+ presentationWebGLDeviceResolvers.resolve(webglDevice2);
797
+ } catch (error) {
798
+ import_core20.log.error(String(error))();
799
+ presentationWebGLDeviceResolvers.resolve(null);
800
+ }
801
+ return presentationWebGLDeviceResolvers.promise;
802
+ }
729
803
  async function makeNullTestDevice() {
730
804
  const nullDeviceResolvers = withResolvers();
731
805
  try {
@@ -739,10 +813,20 @@ async function makeNullTestDevice() {
739
813
  nullDeviceResolvers.resolve(nullDevice);
740
814
  } catch (error) {
741
815
  import_core20.log.error(String(error))();
742
- nullDevicePromise = Promise.resolve(null);
816
+ testDeviceCache.nullDevicePromise = Promise.resolve(null);
743
817
  }
744
818
  return nullDeviceResolvers.promise;
745
819
  }
820
+ function getOrCreateTestDeviceCache() {
821
+ const rootObject = globalThis;
822
+ rootObject[TEST_DEVICE_CACHE_KEY] ||= {
823
+ nullDevicePromise: null,
824
+ webglDevicePromise: null,
825
+ presentationWebglDevicePromise: null,
826
+ webgpuDevicePromise: null
827
+ };
828
+ return rootObject[TEST_DEVICE_CACHE_KEY];
829
+ }
746
830
  function withResolvers() {
747
831
  let resolve;
748
832
  let reject;
@@ -753,11 +837,36 @@ function withResolvers() {
753
837
  return { promise, resolve, reject };
754
838
  }
755
839
 
840
+ // dist/deprecated/sync-test-device.js
841
+ var import_webgl3 = require("@luma.gl/webgl");
842
+ var DEFAULT_CANVAS_CONTEXT_PROPS2 = {
843
+ width: 1,
844
+ height: 1
845
+ };
846
+ function createTestDevice() {
847
+ if (cachedWebglDevice) {
848
+ return cachedWebglDevice;
849
+ }
850
+ if (typeof navigator === "undefined" || typeof document === "undefined" || typeof HTMLCanvasElement === "undefined") {
851
+ return null;
852
+ }
853
+ try {
854
+ cachedWebglDevice = new import_webgl3.WebGLDevice({ createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS2 });
855
+ return cachedWebglDevice;
856
+ } catch (error) {
857
+ console.error(`Failed to created device: ${error.message}`);
858
+ debugger;
859
+ return null;
860
+ }
861
+ }
862
+ var cachedWebglDevice = null;
863
+ var webglDevice = createTestDevice();
864
+
756
865
  // dist/deprecated/classic-animation-loop.js
757
866
  var import_core21 = require("@luma.gl/core");
758
867
  var import_engine = require("@luma.gl/engine");
759
868
  var import_env = require("@probe.gl/env");
760
- var import_webgl3 = require("@luma.gl/webgl");
869
+ var import_webgl4 = require("@luma.gl/webgl");
761
870
  var isPage = (0, import_env.isBrowser)() && typeof document !== "undefined";
762
871
  function getHTMLCanvasElement(canvas) {
763
872
  return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement ? canvas : null;
@@ -1116,7 +1225,7 @@ var ClassicAnimationLoop = class {
1116
1225
  const deviceProps = { ...this.props, ...props, ...this.props.glOptions };
1117
1226
  this.device = await this.onCreateDevice(deviceProps);
1118
1227
  this.gl = this.device.gl;
1119
- (0, import_webgl3.resetGLParameters)(this.gl);
1228
+ (0, import_webgl4.resetGLParameters)(this.gl);
1120
1229
  this._createInfoDiv();
1121
1230
  }
1122
1231
  _createInfoDiv() {
@@ -1217,7 +1326,7 @@ var DEFAULT_TEST_PROPS = {
1217
1326
  imageDiffOptions: void 0
1218
1327
  };
1219
1328
  var TestRunner = class {
1220
- device = webglDevice;
1329
+ device = createTestDevice();
1221
1330
  props;
1222
1331
  isRunning = false;
1223
1332
  testOptions = { ...DEFAULT_TEST_PROPS };
@@ -1509,21 +1618,4 @@ function getLeakedResources(startCounts, endCounts) {
1509
1618
  }
1510
1619
  return leakedResources;
1511
1620
  }
1512
-
1513
- // dist/deprecated/sync-test-device.js
1514
- var import_webgl4 = require("@luma.gl/webgl");
1515
- var DEFAULT_CANVAS_CONTEXT_PROPS2 = {
1516
- width: 1,
1517
- height: 1
1518
- };
1519
- function createTestDevice() {
1520
- try {
1521
- return new import_webgl4.WebGLDevice({ createCanvasContext: DEFAULT_CANVAS_CONTEXT_PROPS2 });
1522
- } catch (error) {
1523
- console.error(`Failed to created device: ${error.message}`);
1524
- debugger;
1525
- return null;
1526
- }
1527
- }
1528
- var webglDevice2 = createTestDevice();
1529
1621
  //# sourceMappingURL=index.cjs.map