@luma.gl/webgpu 9.0.0-alpha.9 → 9.0.0-beta.10

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 (142) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/helpers/accessor-to-format.js +102 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
  4. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  5. package/dist/adapter/helpers/convert-texture-format.js +8 -6
  6. package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
  7. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  8. package/dist/adapter/helpers/get-bind-group.js +61 -52
  9. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
  10. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-vertex-buffer-layout.js +123 -90
  12. package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
  13. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  14. package/dist/adapter/helpers/webgpu-parameters.js +184 -130
  15. package/dist/adapter/resources/webgpu-buffer.d.ts +14 -5
  16. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-buffer.js +117 -70
  18. package/dist/adapter/resources/webgpu-command-encoder.d.ts +13 -14
  19. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-command-encoder.js +83 -65
  21. package/dist/adapter/resources/webgpu-compute-pass.d.ts +19 -13
  22. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pass.js +78 -57
  24. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +16 -6
  25. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-compute-pipeline.js +48 -26
  27. package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
  28. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-external-texture.js +38 -29
  30. package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
  31. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgpu-framebuffer.js +15 -109
  33. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  34. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  35. package/dist/adapter/resources/webgpu-query-set.js +27 -0
  36. package/dist/adapter/resources/webgpu-render-pass.d.ts +14 -7
  37. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-render-pass.js +136 -91
  39. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +63 -23
  40. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgpu-render-pipeline.js +151 -148
  42. package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
  43. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-sampler.js +23 -23
  45. package/dist/adapter/resources/webgpu-shader.d.ts +9 -12
  46. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgpu-shader.js +47 -60
  48. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  49. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  50. package/dist/adapter/resources/webgpu-texture-view.js +35 -0
  51. package/dist/adapter/resources/webgpu-texture.d.ts +20 -10
  52. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-texture.js +133 -105
  54. package/dist/adapter/resources/webgpu-vertex-array.d.ts +27 -0
  55. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  56. package/dist/adapter/resources/webgpu-vertex-array.js +66 -0
  57. package/dist/adapter/webgpu-canvas-context.d.ts +17 -12
  58. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  59. package/dist/adapter/webgpu-canvas-context.js +105 -92
  60. package/dist/adapter/webgpu-device.d.ts +45 -30
  61. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  62. package/dist/adapter/webgpu-device.js +266 -241
  63. package/dist/dist.dev.js +1664 -0
  64. package/dist/dist.min.js +9 -0
  65. package/dist/index.cjs +1432 -0
  66. package/dist/index.cjs.map +7 -0
  67. package/dist/index.d.ts +5 -7
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +10 -8
  70. package/dist.min.js +9 -0
  71. package/package.json +22 -11
  72. package/src/adapter/helpers/accessor-to-format.ts +6 -3
  73. package/src/adapter/helpers/convert-texture-format.ts +5 -2
  74. package/src/adapter/helpers/get-bind-group.ts +30 -14
  75. package/src/adapter/helpers/get-vertex-buffer-layout.ts +73 -39
  76. package/src/adapter/helpers/webgpu-parameters.ts +99 -29
  77. package/src/adapter/resources/webgpu-buffer.ts +85 -17
  78. package/src/adapter/resources/webgpu-command-encoder.ts +93 -58
  79. package/src/adapter/resources/webgpu-compute-pass.ts +56 -32
  80. package/src/adapter/resources/webgpu-compute-pipeline.ts +51 -18
  81. package/src/adapter/resources/webgpu-external-texture.ts +19 -11
  82. package/src/adapter/resources/webgpu-framebuffer.ts +11 -108
  83. package/src/adapter/resources/webgpu-query-set.ts +37 -0
  84. package/src/adapter/resources/webgpu-render-pass.ts +95 -19
  85. package/src/adapter/resources/webgpu-render-pipeline.ts +139 -159
  86. package/src/adapter/resources/webgpu-sampler.ts +10 -7
  87. package/src/adapter/resources/webgpu-shader.ts +30 -35
  88. package/src/adapter/resources/webgpu-texture-view.ts +46 -0
  89. package/src/adapter/resources/webgpu-texture.ts +75 -41
  90. package/src/adapter/resources/webgpu-vertex-array.ts +91 -0
  91. package/src/adapter/webgpu-canvas-context.ts +60 -29
  92. package/src/adapter/webgpu-device.ts +219 -120
  93. package/src/index.ts +8 -9
  94. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  95. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  96. package/dist/adapter/helpers/generate-mipmaps.d.ts +0 -10
  97. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
  98. package/dist/adapter/helpers/generate-mipmaps.js +0 -95
  99. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  100. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  101. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  102. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  106. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  107. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  108. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-query.d.ts +0 -1
  110. package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
  111. package/dist/adapter/resources/webgpu-query.js +0 -2
  112. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  113. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  114. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  115. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  116. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  117. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  118. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  119. package/dist/adapter/webgpu-device.js.map +0 -1
  120. package/dist/adapter/webgpu-types.d.ts +0 -1
  121. package/dist/adapter/webgpu-types.d.ts.map +0 -1
  122. package/dist/adapter/webgpu-types.js +0 -2
  123. package/dist/adapter/webgpu-types.js.map +0 -1
  124. package/dist/bundle.d.ts +0 -2
  125. package/dist/bundle.d.ts.map +0 -1
  126. package/dist/bundle.js +0 -5
  127. package/dist/bundle.js.map +0 -1
  128. package/dist/glsl/glsllang.d.ts +0 -3
  129. package/dist/glsl/glsllang.d.ts.map +0 -1
  130. package/dist/glsl/glsllang.js +0 -10
  131. package/dist/glsl/glsllang.js.map +0 -1
  132. package/dist/index.js.map +0 -1
  133. package/dist/init.d.ts +0 -2
  134. package/dist/init.d.ts.map +0 -1
  135. package/dist/init.js +0 -4
  136. package/dist/init.js.map +0 -1
  137. package/src/adapter/helpers/generate-mipmaps.ts +0 -107
  138. package/src/adapter/resources/webgpu-query.ts +0 -43
  139. package/src/adapter/webgpu-types.ts +0 -0
  140. package/src/bundle.ts +0 -4
  141. package/src/glsl/glsllang.ts +0 -14
  142. package/src/init.ts +0 -4
@@ -1,16 +1,20 @@
1
- /// <reference types="@webgpu/types" />
2
- /// <reference types="offscreencanvas" />
3
- import { Texture, TextureProps, Sampler, SamplerProps } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
5
- import WebGPUSampler from './webgpu-sampler';
6
- export default class WebGPUTexture extends Texture {
1
+ /// <reference types="dist" />
2
+ import { Texture, TextureProps, TextureViewProps, Sampler, SamplerProps } from '@luma.gl/core';
3
+ import type { WebGPUDevice } from "../webgpu-device.js";
4
+ import { WebGPUSampler } from "./webgpu-sampler.js";
5
+ import { WebGPUTextureView } from "./webgpu-texture-view.js";
6
+ export declare class WebGPUTexture extends Texture {
7
7
  readonly device: WebGPUDevice;
8
8
  readonly handle: GPUTexture;
9
- readonly view: GPUTextureView;
9
+ height: number;
10
+ width: number;
10
11
  sampler: WebGPUSampler;
12
+ view: WebGPUTextureView;
11
13
  constructor(device: WebGPUDevice, props: TextureProps);
12
- protected createHandle(): GPUTexture;
13
14
  destroy(): void;
15
+ createView(props: TextureViewProps): WebGPUTextureView;
16
+ protected initialize(props: TextureProps): void;
17
+ protected createHandle(): GPUTexture;
14
18
  /**
15
19
  * Set default sampler
16
20
  * Accept a sampler instance or set of props;
@@ -18,7 +22,10 @@ export default class WebGPUTexture extends Texture {
18
22
  setSampler(sampler: Sampler | SamplerProps): this;
19
23
  setData(options: {
20
24
  data: any;
21
- }): this;
25
+ }): {
26
+ width: number;
27
+ height: number;
28
+ };
22
29
  /** Set image */
23
30
  setImage(options: {
24
31
  source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;
@@ -34,6 +41,9 @@ export default class WebGPUTexture extends Texture {
34
41
  aspect?: 'all' | 'stencil-only' | 'depth-only';
35
42
  colorSpace?: 'srgb';
36
43
  premultipliedAlpha?: boolean;
37
- }): this;
44
+ }): {
45
+ width: number;
46
+ height: number;
47
+ };
38
48
  }
39
49
  //# sourceMappingURL=webgpu-texture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-texture.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":[],"mappings":";;AACA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAS,MAAM,cAAc,CAAC;AAElF,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAW7C,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAQ;gBASlB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY;IA+BrD,SAAS,CAAC,YAAY,IAAI,UAAU;IAyBpC,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI;IAKjD,OAAO,CAAC,OAAO,EAAE;QACf,IAAI,EAAE,GAAG,CAAC;KACX;IAID,gBAAgB;IAChB,QAAQ,CAAC,OAA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G,iBAAiB;IAItD,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAwC/C,SAAS,CAAC,YAAY,IAAI,UAAU;IAsBpC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI;IAMjD,OAAO,CAAC,OAAO,EAAE;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC;;;;IAI5B,gBAAgB;IAChB,QAAQ,CAAC,OAAO,EAAE;QAChB,MAAM,EAAE,WAAW,GAAG,iBAAiB,GAAG,eAAe,CAAC;QAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,MAAM,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC;QAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GAAG;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC;CA2HpC"}
@@ -1,111 +1,139 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Texture } from '@luma.gl/api';
3
- import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
4
- import WebGPUSampler from './webgpu-sampler';
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Texture } from '@luma.gl/core';
5
+ import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
6
+ import { WebGPUSampler } from "./webgpu-sampler.js";
7
+ import { WebGPUTextureView } from "./webgpu-texture-view.js";
5
8
  const BASE_DIMENSIONS = {
6
- '1d': '1d',
7
- '2d': '2d',
8
- '2d-array': '2d',
9
- 'cube': '2d',
10
- 'cube-array': '2d',
11
- '3d': '3d'
9
+ '1d': '1d',
10
+ '2d': '2d',
11
+ '2d-array': '2d',
12
+ cube: '2d',
13
+ 'cube-array': '2d',
14
+ '3d': '3d'
12
15
  };
13
- export default class WebGPUTexture extends Texture {
14
- constructor(device, props) {
15
- super(device, props);
16
-
17
- _defineProperty(this, "device", void 0);
18
-
19
- _defineProperty(this, "handle", void 0);
20
-
21
- _defineProperty(this, "view", void 0);
22
-
23
- _defineProperty(this, "sampler", null);
24
-
25
- if (typeof this.props.format === 'number') {
26
- throw new Error('number format');
16
+ export class WebGPUTexture extends Texture {
17
+ device;
18
+ handle;
19
+ height = 1;
20
+ width = 1;
21
+ sampler;
22
+ view;
23
+ // static async createFromImageURL(src, usage = 0) {
24
+ // const img = document.createElement('img');
25
+ // img.src = src;
26
+ // await img.decode();
27
+ // return WebGPUTexture(img, usage);
28
+ // }
29
+ constructor(device, props) {
30
+ super(device, props);
31
+ this.device = device;
32
+ if (props.data instanceof Promise) {
33
+ props.data.then(resolvedImageData => {
34
+ // @ts-expect-error
35
+ this.props = { ...props, data: resolvedImageData };
36
+ this.initialize(this.props);
37
+ });
38
+ return;
39
+ }
40
+ this.initialize(props);
27
41
  }
28
-
29
- this.device = device;
30
- this.handle = this.props.handle || this.createHandle();
31
-
32
- if (this.props.data) {
33
- this.setData({
34
- data: this.props.data
35
- });
42
+ destroy() {
43
+ this.handle?.destroy();
44
+ // @ts-expect-error readonly
45
+ this.handle = null;
36
46
  }
37
-
38
- this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
39
- this.view = this.handle.createView({});
40
- }
41
-
42
- createHandle() {
43
- var _this$props$data, _this$props$data2;
44
-
45
- if (typeof this.props.format === 'number') {
46
- throw new Error('number format');
47
+ createView(props) {
48
+ return new WebGPUTextureView(this.device, { ...props, texture: this });
49
+ }
50
+ initialize(props) {
51
+ // @ts-expect-error
52
+ this.handle = this.props.handle || this.createHandle();
53
+ this.handle.label ||= this.id;
54
+ if (this.props.data) {
55
+ this.setData({ data: this.props.data });
56
+ }
57
+ this.width = this.handle.width;
58
+ this.height = this.handle.height;
59
+ // Why not just read all properties directly from the texture
60
+ // this.depthOrArrayLayers = this.handle.depthOrArrayLayers;
61
+ // this.mipLevelCount = this.handle.mipLevelCount;
62
+ // this.sampleCount = this.handle.sampleCount;
63
+ // this.dimension = this.handle.dimension;
64
+ // this.format = this.handle.format;
65
+ // this.usage = this.handle.usage;
66
+ // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
67
+ // this.setSampler(props.sampler);
68
+ this.sampler =
69
+ props.sampler instanceof WebGPUSampler
70
+ ? props.sampler
71
+ : new WebGPUSampler(this.device, props.sampler);
72
+ // TODO - To support texture arrays we need to create custom views...
73
+ // But we are not ready to expose TextureViews to the public API.
74
+ // @ts-expect-error
75
+ this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
76
+ // format: this.props.format,
77
+ // dimension: this.props.dimension,
78
+ // aspect = "all";
79
+ // baseMipLevel: 0;
80
+ // mipLevelCount;
81
+ // baseArrayLayer = 0;
82
+ // arrayLayerCount;
83
+ }
84
+ createHandle() {
85
+ // Deduce size from data - TODO this is a hack
86
+ // @ts-expect-error
87
+ const width = this.props.width || this.props.data?.width || 1;
88
+ // @ts-expect-error
89
+ const height = this.props.height || this.props.data?.height || 1;
90
+ return this.device.handle.createTexture({
91
+ label: this.id,
92
+ size: {
93
+ width,
94
+ height,
95
+ depthOrArrayLayers: this.props.depth
96
+ },
97
+ dimension: BASE_DIMENSIONS[this.props.dimension],
98
+ format: getWebGPUTextureFormat(this.props.format),
99
+ usage: this.props.usage,
100
+ mipLevelCount: this.props.mipLevels,
101
+ sampleCount: this.props.samples
102
+ });
103
+ }
104
+ /**
105
+ * Set default sampler
106
+ * Accept a sampler instance or set of props;
107
+ */
108
+ setSampler(sampler) {
109
+ this.sampler =
110
+ sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
111
+ return this;
112
+ }
113
+ setData(options) {
114
+ return this.setImage({ source: options.data });
115
+ }
116
+ /** Set image */
117
+ setImage(options) {
118
+ const { source, width = options.source.width, height = options.source.height, depth = 1, sourceX = 0, sourceY = 0, mipLevel = 0, x = 0, y = 0, z = 0, aspect = 'all', colorSpace = 'srgb', premultipliedAlpha = false } = options;
119
+ // TODO - max out width
120
+ this.device.handle.queue.copyExternalImageToTexture(
121
+ // source: GPUImageCopyExternalImage
122
+ {
123
+ source,
124
+ origin: [sourceX, sourceY]
125
+ },
126
+ // destination: GPUImageCopyTextureTagged
127
+ {
128
+ texture: this.handle,
129
+ origin: [x, y, z],
130
+ mipLevel,
131
+ aspect,
132
+ colorSpace,
133
+ premultipliedAlpha
134
+ },
135
+ // copySize: GPUExtent3D
136
+ [width, height, depth]);
137
+ return { width, height };
47
138
  }
48
-
49
- const width = this.props.width || ((_this$props$data = this.props.data) === null || _this$props$data === void 0 ? void 0 : _this$props$data.width) || 1;
50
- const height = this.props.height || ((_this$props$data2 = this.props.data) === null || _this$props$data2 === void 0 ? void 0 : _this$props$data2.height) || 1;
51
- return this.device.handle.createTexture({
52
- size: {
53
- width,
54
- height,
55
- depthOrArrayLayers: this.props.depth
56
- },
57
- dimension: BASE_DIMENSIONS[this.props.dimension],
58
- format: getWebGPUTextureFormat(this.props.format),
59
- usage: this.props.usage,
60
- mipLevelCount: this.props.mipLevels,
61
- sampleCount: this.props.samples
62
- });
63
- }
64
-
65
- destroy() {
66
- this.handle.destroy();
67
- }
68
-
69
- setSampler(sampler) {
70
- this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
71
- return this;
72
- }
73
-
74
- setData(options) {
75
- return this.setImage({
76
- source: options.data
77
- });
78
- }
79
-
80
- setImage(options) {
81
- const {
82
- source,
83
- width = options.source.width,
84
- height = options.source.height,
85
- depth = 1,
86
- sourceX = 0,
87
- sourceY = 0,
88
- mipLevel = 0,
89
- x = 0,
90
- y = 0,
91
- z = 0,
92
- aspect = 'all',
93
- colorSpace = 'srgb',
94
- premultipliedAlpha = false
95
- } = options;
96
- this.device.handle.queue.copyExternalImageToTexture({
97
- source,
98
- origin: [sourceX, sourceY]
99
- }, {
100
- texture: this.handle,
101
- origin: [x, y, z],
102
- mipLevel,
103
- aspect,
104
- colorSpace,
105
- premultipliedAlpha
106
- }, [width, height, depth]);
107
- return this;
108
- }
109
-
110
139
  }
111
- //# sourceMappingURL=webgpu-texture.js.map
@@ -0,0 +1,27 @@
1
+ import type { Device, Buffer, VertexArrayProps, RenderPass } from '@luma.gl/core';
2
+ import { VertexArray } from '@luma.gl/core';
3
+ import { WebGPUDevice } from "../webgpu-device.js";
4
+ /** VertexArrayObject wrapper */
5
+ export declare class WebGPUVertexArray extends VertexArray {
6
+ get [Symbol.toStringTag](): string;
7
+ readonly device: WebGPUDevice;
8
+ /** Vertex Array is a helper class under WebGPU */
9
+ readonly handle: never;
10
+ constructor(device: WebGPUDevice, props?: VertexArrayProps);
11
+ destroy(): void;
12
+ /**
13
+ * Set an elements buffer, for indexed rendering.
14
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
15
+ */
16
+ setIndexBuffer(buffer: Buffer | null): void;
17
+ /** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
18
+ setBuffer(bufferSlot: number, buffer: Buffer): void;
19
+ bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void;
20
+ unbindAfterRender(renderPass: RenderPass): void;
21
+ /**
22
+ * @deprecated is this even an issue for WebGPU?
23
+ * Attribute 0 can not be disable on most desktop OpenGL based browsers
24
+ */
25
+ static isConstantAttributeZeroSupported(device: Device): boolean;
26
+ }
27
+ //# sourceMappingURL=webgpu-vertex-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu-vertex-array.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-vertex-array.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAChF,OAAO,EAAC,WAAW,EAAM,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAC,YAAY,EAAC,4BAAyB;AAK9C,gCAAgC;AAChC,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;gBAGX,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,gBAAgB;IAKjD,OAAO,IAAI,IAAI;IAExB;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAK3C,oGAAoG;IACpG,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAS1C,gBAAgB,CACvB,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI;IAqBE,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQxD;;;OAGG;IACH,MAAM,CAAC,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAGjE"}
@@ -0,0 +1,66 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { VertexArray, log } from '@luma.gl/core';
5
+ import { getBrowser } from '@probe.gl/env';
6
+ /** VertexArrayObject wrapper */
7
+ export class WebGPUVertexArray extends VertexArray {
8
+ get [Symbol.toStringTag]() {
9
+ return 'WebGPUVertexArray';
10
+ }
11
+ device;
12
+ /** Vertex Array is a helper class under WebGPU */
13
+ handle;
14
+ // Create a VertexArray
15
+ constructor(device, props) {
16
+ super(device, props);
17
+ this.device = device;
18
+ }
19
+ destroy() { }
20
+ /**
21
+ * Set an elements buffer, for indexed rendering.
22
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
23
+ */
24
+ setIndexBuffer(buffer) {
25
+ // assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
26
+ this.indexBuffer = buffer;
27
+ }
28
+ /** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
29
+ setBuffer(bufferSlot, buffer) {
30
+ // Sanity check target
31
+ // if (buffer.glUsage === GL.ELEMENT_ARRAY_BUFFER) {
32
+ // throw new Error('Use setIndexBuffer');
33
+ // }
34
+ this.attributes[bufferSlot] = buffer;
35
+ }
36
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
37
+ const webgpuRenderPass = renderPass;
38
+ const webgpuIndexBuffer = this.indexBuffer;
39
+ if (webgpuIndexBuffer?.handle) {
40
+ // Note we can't unset an index buffer
41
+ log.warn('setting index buffer', webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType)();
42
+ webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);
43
+ }
44
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
45
+ const webgpuBuffer = this.attributes[location];
46
+ if (webgpuBuffer?.handle) {
47
+ log.warn(`setting vertex buffer ${location}`, webgpuBuffer?.handle)();
48
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle);
49
+ }
50
+ }
51
+ // TODO - emit warnings/errors/throw if constants have been set on this vertex array
52
+ }
53
+ unbindAfterRender(renderPass) {
54
+ // On WebGPU we don't need to unbind.
55
+ // In fact we can't easily do it. setIndexBuffer/setVertexBuffer don't accept null.
56
+ // Unbinding presumably happens automatically when the render pass is ended.
57
+ }
58
+ // DEPRECATED METHODS
59
+ /**
60
+ * @deprecated is this even an issue for WebGPU?
61
+ * Attribute 0 can not be disable on most desktop OpenGL based browsers
62
+ */
63
+ static isConstantAttributeZeroSupported(device) {
64
+ return getBrowser() === 'Chrome';
65
+ }
66
+ }
@@ -1,24 +1,27 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { Texture, TextureFormat, CanvasContextProps } from '@luma.gl/api';
3
- import { CanvasContext } from '@luma.gl/api';
4
- import WebGPUDevice from './webgpu-device';
5
- import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
1
+ /// <reference types="dist" />
2
+ import type { Texture, TextureFormat, CanvasContextProps } from '@luma.gl/core';
3
+ import { CanvasContext } from '@luma.gl/core';
4
+ import { WebGPUDevice } from "./webgpu-device.js";
5
+ import { WebGPUFramebuffer } from "./resources/webgpu-framebuffer.js";
6
+ import { WebGPUTexture } from "./resources/webgpu-texture.js";
6
7
  /**
7
- * Holds a WebGPU Canvas Context which handles resizing etc
8
+ * Holds a WebGPU Canvas Context
9
+ * The primary job of the CanvasContext is to generate textures for rendering into the current canvas
10
+ * It also manages canvas sizing calculations and resizing.
8
11
  */
9
- export default class WebGPUCanvasContext extends CanvasContext {
12
+ export declare class WebGPUCanvasContext extends CanvasContext {
10
13
  readonly device: WebGPUDevice;
11
14
  readonly gpuCanvasContext: GPUCanvasContext;
15
+ /** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
12
16
  readonly format: TextureFormat;
13
- width: number;
14
- height: number;
17
+ /** Default stencil format for depth textures */
15
18
  depthStencilFormat: TextureFormat;
16
- sampleCount: number;
17
19
  private depthStencilAttachment;
18
20
  constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps);
21
+ /** Destroy any textures produced while configured and remove the context configuration. */
19
22
  destroy(): void;
20
23
  /** Update framebuffer with properly resized "swap chain" texture views */
21
- getCurrentFramebuffer(): WEBGPUFramebuffer;
24
+ getCurrentFramebuffer(): WebGPUFramebuffer;
22
25
  /** Resizes and updates render targets if necessary */
23
26
  update(): void;
24
27
  resize(options?: {
@@ -26,7 +29,9 @@ export default class WebGPUCanvasContext extends CanvasContext {
26
29
  height?: number;
27
30
  useDevicePixels?: boolean | number;
28
31
  }): void;
32
+ /** Wrap the current canvas context texture in a luma.gl texture */
33
+ getCurrentTexture(): WebGPUTexture;
29
34
  /** We build render targets on demand (i.e. not when size changes but when about to render) */
30
- _createDepthStencilAttachment(): Texture;
35
+ _createDepthStencilAttachment(): Texture<import("@luma.gl/core").TextureProps>;
31
36
  }
32
37
  //# sourceMappingURL=webgpu-canvas-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAM,MAAM,cAAc,CAAC;AAEhD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAM;IACnB,MAAM,EAAE,MAAM,CAAM;IACpB,kBAAkB,EAAE,aAAa,CAAiB;IAClD,WAAW,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,sBAAsB,CAAwB;gBAE1C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAOhF,OAAO;IAIP,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN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