@luma.gl/webgpu 9.0.0-alpha.14 → 9.0.0-alpha.16

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 (179) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +100 -1
  2. package/dist/adapter/helpers/convert-texture-format.js +5 -6
  3. package/dist/adapter/helpers/generate-mipmaps.js +88 -92
  4. package/dist/adapter/helpers/get-bind-group.js +54 -48
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.js +97 -84
  6. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  7. package/dist/adapter/helpers/webgpu-parameters.js +181 -129
  8. package/dist/adapter/resources/webgpu-buffer.js +57 -73
  9. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-command-encoder.js +47 -63
  11. package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
  12. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgpu-compute-pass.js +51 -55
  14. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-compute-pipeline.js +22 -24
  16. package/dist/adapter/resources/webgpu-external-texture.js +26 -27
  17. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgpu-framebuffer.js +89 -103
  19. package/dist/adapter/resources/webgpu-query.js +42 -1
  20. package/dist/adapter/resources/webgpu-render-pass.d.ts +1 -1
  21. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-render-pass.js +64 -89
  23. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-render-pipeline.js +158 -154
  25. package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
  26. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgpu-sampler.js +16 -22
  28. package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
  29. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-shader.js +47 -58
  31. package/dist/adapter/resources/webgpu-texture.d.ts +0 -1
  32. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgpu-texture.js +100 -103
  34. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  35. package/dist/adapter/webgpu-canvas-context.js +77 -90
  36. package/dist/adapter/webgpu-device.js +215 -242
  37. package/dist/adapter/webgpu-types.js +0 -2
  38. package/dist/bundle.js +1 -2
  39. package/dist/dist.js +8051 -0
  40. package/dist/dist.min.js +1 -0
  41. package/dist/es5/adapter/helpers/accessor-to-format.js +2 -0
  42. package/dist/es5/adapter/helpers/accessor-to-format.js.map +1 -0
  43. package/dist/es5/adapter/helpers/convert-texture-format.js +13 -0
  44. package/dist/es5/adapter/helpers/convert-texture-format.js.map +1 -0
  45. package/dist/es5/adapter/helpers/generate-mipmaps.js +103 -0
  46. package/dist/es5/adapter/helpers/generate-mipmaps.js.map +1 -0
  47. package/dist/es5/adapter/helpers/get-bind-group.js +66 -0
  48. package/dist/es5/adapter/helpers/get-bind-group.js.map +1 -0
  49. package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js +149 -0
  50. package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  51. package/dist/es5/adapter/helpers/webgpu-parameters.js +150 -0
  52. package/dist/es5/adapter/helpers/webgpu-parameters.js.map +1 -0
  53. package/dist/es5/adapter/resources/webgpu-buffer.js +131 -0
  54. package/dist/es5/adapter/resources/webgpu-buffer.js.map +1 -0
  55. package/dist/es5/adapter/resources/webgpu-command-encoder.js +90 -0
  56. package/dist/es5/adapter/resources/webgpu-command-encoder.js.map +1 -0
  57. package/dist/es5/adapter/resources/webgpu-compute-pass.js +85 -0
  58. package/dist/es5/adapter/resources/webgpu-compute-pass.js.map +1 -0
  59. package/dist/es5/adapter/resources/webgpu-compute-pipeline.js +48 -0
  60. package/dist/es5/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
  61. package/dist/es5/adapter/resources/webgpu-external-texture.js +50 -0
  62. package/dist/es5/adapter/resources/webgpu-external-texture.js.map +1 -0
  63. package/dist/es5/adapter/resources/webgpu-framebuffer.js +126 -0
  64. package/dist/es5/adapter/resources/webgpu-framebuffer.js.map +1 -0
  65. package/dist/es5/adapter/resources/webgpu-query.js +2 -0
  66. package/dist/es5/adapter/resources/webgpu-query.js.map +1 -0
  67. package/dist/es5/adapter/resources/webgpu-render-pass.js +124 -0
  68. package/dist/es5/adapter/resources/webgpu-render-pass.js.map +1 -0
  69. package/dist/es5/adapter/resources/webgpu-render-pipeline.js +185 -0
  70. package/dist/es5/adapter/resources/webgpu-render-pipeline.js.map +1 -0
  71. package/dist/es5/adapter/resources/webgpu-sampler.js +45 -0
  72. package/dist/es5/adapter/resources/webgpu-sampler.js.map +1 -0
  73. package/dist/es5/adapter/resources/webgpu-shader.js +125 -0
  74. package/dist/es5/adapter/resources/webgpu-shader.js.map +1 -0
  75. package/dist/es5/adapter/resources/webgpu-texture.js +138 -0
  76. package/dist/es5/adapter/resources/webgpu-texture.js.map +1 -0
  77. package/dist/es5/adapter/webgpu-canvas-context.js +111 -0
  78. package/dist/es5/adapter/webgpu-canvas-context.js.map +1 -0
  79. package/dist/es5/adapter/webgpu-device.js +317 -0
  80. package/dist/es5/adapter/webgpu-device.js.map +1 -0
  81. package/dist/es5/adapter/webgpu-types.js +2 -0
  82. package/dist/es5/adapter/webgpu-types.js.map +1 -0
  83. package/dist/es5/bundle.js +6 -0
  84. package/dist/es5/bundle.js.map +1 -0
  85. package/dist/es5/glsl/glsllang.js +47 -0
  86. package/dist/es5/glsl/glsllang.js.map +1 -0
  87. package/dist/es5/index.js +44 -0
  88. package/dist/es5/index.js.map +1 -0
  89. package/dist/es5/init.js +7 -0
  90. package/dist/es5/init.js.map +1 -0
  91. package/dist/esm/adapter/helpers/accessor-to-format.js +2 -0
  92. package/dist/esm/adapter/helpers/accessor-to-format.js.map +1 -0
  93. package/dist/esm/adapter/helpers/convert-texture-format.js +7 -0
  94. package/dist/esm/adapter/helpers/convert-texture-format.js.map +1 -0
  95. package/dist/esm/adapter/helpers/generate-mipmaps.js +88 -0
  96. package/dist/esm/adapter/helpers/generate-mipmaps.js.map +1 -0
  97. package/dist/esm/adapter/helpers/get-bind-group.js +51 -0
  98. package/dist/esm/adapter/helpers/get-bind-group.js.map +1 -0
  99. package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js +83 -0
  100. package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  101. package/dist/esm/adapter/helpers/webgpu-parameters.js +137 -0
  102. package/dist/esm/adapter/helpers/webgpu-parameters.js.map +1 -0
  103. package/dist/esm/adapter/resources/webgpu-buffer.js +70 -0
  104. package/dist/esm/adapter/resources/webgpu-buffer.js.map +1 -0
  105. package/dist/esm/adapter/resources/webgpu-command-encoder.js +49 -0
  106. package/dist/esm/adapter/resources/webgpu-command-encoder.js.map +1 -0
  107. package/dist/esm/adapter/resources/webgpu-compute-pass.js +44 -0
  108. package/dist/esm/adapter/resources/webgpu-compute-pass.js.map +1 -0
  109. package/dist/esm/adapter/resources/webgpu-compute-pipeline.js +23 -0
  110. package/dist/esm/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
  111. package/dist/esm/adapter/resources/webgpu-external-texture.js +23 -0
  112. package/dist/esm/adapter/resources/webgpu-external-texture.js.map +1 -0
  113. package/dist/esm/adapter/resources/webgpu-framebuffer.js +93 -0
  114. package/dist/esm/adapter/resources/webgpu-framebuffer.js.map +1 -0
  115. package/dist/esm/adapter/resources/webgpu-query.js +2 -0
  116. package/dist/esm/adapter/resources/webgpu-query.js.map +1 -0
  117. package/dist/esm/adapter/resources/webgpu-render-pass.js +79 -0
  118. package/dist/esm/adapter/resources/webgpu-render-pass.js.map +1 -0
  119. package/dist/esm/adapter/resources/webgpu-render-pipeline.js +130 -0
  120. package/dist/esm/adapter/resources/webgpu-render-pipeline.js.map +1 -0
  121. package/dist/esm/adapter/resources/webgpu-sampler.js +20 -0
  122. package/dist/esm/adapter/resources/webgpu-sampler.js.map +1 -0
  123. package/dist/esm/adapter/resources/webgpu-shader.js +50 -0
  124. package/dist/esm/adapter/resources/webgpu-shader.js.map +1 -0
  125. package/dist/esm/adapter/resources/webgpu-texture.js +95 -0
  126. package/dist/esm/adapter/resources/webgpu-texture.js.map +1 -0
  127. package/dist/esm/adapter/webgpu-canvas-context.js +74 -0
  128. package/dist/esm/adapter/webgpu-canvas-context.js.map +1 -0
  129. package/dist/esm/adapter/webgpu-device.js +196 -0
  130. package/dist/esm/adapter/webgpu-device.js.map +1 -0
  131. package/dist/esm/adapter/webgpu-types.js +2 -0
  132. package/dist/esm/adapter/webgpu-types.js.map +1 -0
  133. package/dist/esm/bundle.js +4 -0
  134. package/dist/esm/bundle.js.map +1 -0
  135. package/dist/esm/glsl/glsllang.js +9 -0
  136. package/dist/esm/glsl/glsllang.js.map +1 -0
  137. package/dist/esm/index.js +8 -0
  138. package/dist/esm/index.js.map +1 -0
  139. package/dist/esm/init.js +4 -0
  140. package/dist/esm/init.js.map +1 -0
  141. package/dist/glsl/glsllang.js +9 -7
  142. package/dist/index.js +8 -6
  143. package/dist/init.js +1 -2
  144. package/package.json +8 -8
  145. package/src/adapter/helpers/webgpu-parameters.ts +7 -2
  146. package/src/adapter/resources/webgpu-command-encoder.ts +2 -1
  147. package/src/adapter/resources/webgpu-compute-pass.ts +4 -4
  148. package/src/adapter/resources/webgpu-compute-pipeline.ts +2 -1
  149. package/src/adapter/resources/webgpu-framebuffer.ts +3 -2
  150. package/src/adapter/resources/webgpu-render-pass.ts +2 -2
  151. package/src/adapter/resources/webgpu-render-pipeline.ts +2 -1
  152. package/src/adapter/resources/webgpu-shader.ts +1 -1
  153. package/src/adapter/webgpu-canvas-context.ts +3 -2
  154. package/src/adapter/webgpu-device.ts +2 -2
  155. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  156. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  157. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  158. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  159. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  160. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  161. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  162. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  163. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  164. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  165. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  166. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  167. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  168. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  169. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  170. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  171. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  172. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  173. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  174. package/dist/adapter/webgpu-device.js.map +0 -1
  175. package/dist/adapter/webgpu-types.js.map +0 -1
  176. package/dist/bundle.js.map +0 -1
  177. package/dist/glsl/glsllang.js.map +0 -1
  178. package/dist/index.js.map +0 -1
  179. package/dist/init.js.map +0 -1
@@ -1,111 +1,108 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ // luma.gl, MIT license
2
2
  import { Texture } from '@luma.gl/api';
3
- import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
4
- import WebGPUSampler from './webgpu-sampler';
3
+ import { getWebGPUTextureFormat } from '../helpers/convert-texture-format.js';
4
+ import WebGPUSampler from './webgpu-sampler.js';
5
5
  const BASE_DIMENSIONS = {
6
- '1d': '1d',
7
- '2d': '2d',
8
- '2d-array': '2d',
9
- 'cube': '2d',
10
- 'cube-array': '2d',
11
- '3d': '3d'
6
+ '1d': '1d',
7
+ '2d': '2d',
8
+ '2d-array': '2d',
9
+ 'cube': '2d',
10
+ 'cube-array': '2d',
11
+ '3d': '3d'
12
12
  };
13
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", void 0);
24
-
25
- if (typeof this.props.format === 'number') {
26
- throw new Error('number format');
14
+ // static async createFromImageURL(src, usage = 0) {
15
+ // const img = document.createElement('img');
16
+ // img.src = src;
17
+ // await img.decode();
18
+ // return WebGPUTexture(img, usage);
19
+ // }
20
+ constructor(device, props) {
21
+ super(device, props);
22
+ if (typeof this.props.format === 'number') {
23
+ throw new Error('number format');
24
+ }
25
+ this.device = device;
26
+ this.handle = this.props.handle || this.createHandle();
27
+ if (this.props.data) {
28
+ this.setData({ data: this.props.data });
29
+ }
30
+ // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
31
+ // this.setSampler(props.sampler);
32
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
33
+ // TODO - To support texture arrays we need to create custom views...
34
+ // But we are not ready to expose TextureViews to the public API.
35
+ this.view = this.handle.createView({
36
+ // format: this.props.format,
37
+ // dimension: this.props.dimension,
38
+ // aspect = "all";
39
+ // baseMipLevel: 0;
40
+ // mipLevelCount;
41
+ // baseArrayLayer = 0;
42
+ // arrayLayerCount;
43
+ });
27
44
  }
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
- });
45
+ createHandle() {
46
+ if (typeof this.props.format === 'number') {
47
+ throw new Error('number format');
48
+ }
49
+ // Deduce size from data - TODO this is a hack
50
+ // @ts-expect-error
51
+ const width = this.props.width || this.props.data?.width || 1;
52
+ // @ts-expect-error
53
+ const height = this.props.height || this.props.data?.height || 1;
54
+ return this.device.handle.createTexture({
55
+ size: {
56
+ width,
57
+ height,
58
+ depthOrArrayLayers: this.props.depth
59
+ },
60
+ dimension: BASE_DIMENSIONS[this.props.dimension],
61
+ format: getWebGPUTextureFormat(this.props.format),
62
+ usage: this.props.usage,
63
+ mipLevelCount: this.props.mipLevels,
64
+ sampleCount: this.props.samples
65
+ });
36
66
  }
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');
67
+ destroy() {
68
+ this.handle.destroy();
69
+ }
70
+ /**
71
+ * Set default sampler
72
+ * Accept a sampler instance or set of props;
73
+ */
74
+ setSampler(sampler) {
75
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
76
+ return this;
77
+ }
78
+ setData(options) {
79
+ return this.setImage({ source: options.data });
80
+ }
81
+ /** Set image */
82
+ setImage(options) {
83
+ 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;
84
+ // TODO - max out width
85
+ this.device.handle.queue.copyExternalImageToTexture(
86
+ // source: GPUImageCopyExternalImage
87
+ {
88
+ source,
89
+ origin: [sourceX, sourceY]
90
+ },
91
+ // destination: GPUImageCopyTextureTagged
92
+ {
93
+ texture: this.handle,
94
+ origin: [x, y, z],
95
+ mipLevel,
96
+ aspect,
97
+ colorSpace,
98
+ premultipliedAlpha
99
+ },
100
+ // copySize: GPUExtent3D
101
+ [
102
+ width,
103
+ height,
104
+ depth
105
+ ]);
106
+ return this;
47
107
  }
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
108
  }
111
- //# sourceMappingURL=webgpu-texture.js.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,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;IAYhF,OAAO,IAAI,IAAI;IAIf,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAI7F,8FAA8F;IAC9F,6BAA6B;CAY9B"}
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,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;IAahF,OAAO,IAAI,IAAI;IAIf,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAI7F,8FAA8F;IAC9F,6BAA6B;CAY9B"}
@@ -1,96 +1,83 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
1
  import { CanvasContext, log } from '@luma.gl/api';
3
- import { getWebGPUTextureFormat } from './helpers/convert-texture-format';
4
- import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
2
+ import { getWebGPUTextureFormat } from './helpers/convert-texture-format.js';
3
+ import WEBGPUFramebuffer from './resources/webgpu-framebuffer.js';
4
+ /**
5
+ * Holds a WebGPU Canvas Context which handles resizing etc
6
+ */
5
7
  export default class WebGPUCanvasContext extends CanvasContext {
6
- constructor(device, adapter, props) {
7
- super(props);
8
-
9
- _defineProperty(this, "device", void 0);
10
-
11
- _defineProperty(this, "gpuCanvasContext", void 0);
12
-
13
- _defineProperty(this, "format", void 0);
14
-
15
- _defineProperty(this, "depthStencilFormat", 'depth24plus');
16
-
17
- _defineProperty(this, "sampleCount", 1);
18
-
19
- _defineProperty(this, "depthStencilAttachment", null);
20
-
21
- this.device = device;
22
- this.width = -1;
23
- this.height = -1;
24
-
25
- this._setAutoCreatedCanvasId("".concat(this.device.id, "-canvas"));
26
-
27
- this.gpuCanvasContext = this.canvas.getContext('webgpu');
28
- this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
29
- }
30
-
31
- destroy() {
32
- this.gpuCanvasContext.unconfigure();
33
- }
34
-
35
- getCurrentFramebuffer() {
36
- this.update();
37
- const currentColorAttachment = this.device.createTexture({
38
- id: 'default-render-target',
39
- handle: this.gpuCanvasContext.getCurrentTexture(),
40
- format: this.format,
41
- width: this.width,
42
- height: this.height
43
- });
44
-
45
- this._createDepthStencilAttachment();
46
-
47
- return new WEBGPUFramebuffer(this.device, {
48
- colorAttachments: [currentColorAttachment],
49
- depthStencilAttachment: this.depthStencilAttachment
50
- });
51
- }
52
-
53
- update() {
54
- const [width, height] = this.getPixelSize();
55
- const sizeChanged = width !== this.width || height !== this.height;
56
-
57
- if (sizeChanged) {
58
- this.width = width;
59
- this.height = height;
60
-
61
- if (this.depthStencilAttachment) {
62
- this.depthStencilAttachment.destroy();
8
+ constructor(device, adapter, props) {
9
+ super(props);
10
+ this.depthStencilFormat = 'depth24plus';
11
+ this.sampleCount = 1;
63
12
  this.depthStencilAttachment = null;
64
- }
65
-
66
- this.gpuCanvasContext.configure({
67
- device: this.device.handle,
68
- format: getWebGPUTextureFormat(this.format),
69
- size: [this.width, this.height],
70
- colorSpace: this.props.colorSpace,
71
- compositingAlphaMode: this.props.compositingAlphaMode
72
- });
73
- log.log(1, "Resized to ".concat(this.width, "x").concat(this.height, "px"))();
13
+ this.device = device;
14
+ // TODO - hack to trigger resize?
15
+ this.width = -1;
16
+ this.height = -1;
17
+ this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
18
+ this.gpuCanvasContext = this.canvas.getContext('webgpu');
19
+ // @ts-expect-error TODO this has been replaced
20
+ this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
74
21
  }
75
- }
76
-
77
- resize(options) {
78
- this.update();
79
- }
80
-
81
- _createDepthStencilAttachment() {
82
- if (!this.depthStencilAttachment) {
83
- this.depthStencilAttachment = this.device.createTexture({
84
- id: 'depth-stencil-target',
85
- format: this.depthStencilFormat,
86
- width: this.width,
87
- height: this.height,
88
- usage: GPUTextureUsage.RENDER_ATTACHMENT
89
- });
22
+ destroy() {
23
+ this.gpuCanvasContext.unconfigure();
24
+ }
25
+ /** Update framebuffer with properly resized "swap chain" texture views */
26
+ getCurrentFramebuffer() {
27
+ // Ensure the canvas context size is updated
28
+ this.update();
29
+ // Wrap the current canvas context texture in a luma.gl texture
30
+ const currentColorAttachment = this.device.createTexture({
31
+ id: 'default-render-target',
32
+ handle: this.gpuCanvasContext.getCurrentTexture(),
33
+ format: this.format,
34
+ width: this.width,
35
+ height: this.height
36
+ });
37
+ // Resize the depth stencil attachment
38
+ this._createDepthStencilAttachment();
39
+ return new WEBGPUFramebuffer(this.device, {
40
+ colorAttachments: [currentColorAttachment],
41
+ depthStencilAttachment: this.depthStencilAttachment
42
+ });
43
+ }
44
+ /** Resizes and updates render targets if necessary */
45
+ update() {
46
+ const [width, height] = this.getPixelSize();
47
+ const sizeChanged = width !== this.width || height !== this.height;
48
+ if (sizeChanged) {
49
+ this.width = width;
50
+ this.height = height;
51
+ if (this.depthStencilAttachment) {
52
+ this.depthStencilAttachment.destroy();
53
+ this.depthStencilAttachment = null;
54
+ }
55
+ // Reconfigure the canvas size.
56
+ // https://www.w3.org/TR/webgpu/#canvas-configuration
57
+ this.gpuCanvasContext.configure({
58
+ device: this.device.handle,
59
+ format: getWebGPUTextureFormat(this.format),
60
+ // size: [this.width, this.height],
61
+ colorSpace: this.props.colorSpace,
62
+ alphaMode: this.props.alphaMode
63
+ });
64
+ log.log(1, `Resized to ${this.width}x${this.height}px`)();
65
+ }
66
+ }
67
+ resize(options) {
68
+ this.update();
69
+ }
70
+ /** We build render targets on demand (i.e. not when size changes but when about to render) */
71
+ _createDepthStencilAttachment() {
72
+ if (!this.depthStencilAttachment) {
73
+ this.depthStencilAttachment = this.device.createTexture({
74
+ id: 'depth-stencil-target',
75
+ format: this.depthStencilFormat,
76
+ width: this.width,
77
+ height: this.height,
78
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
79
+ });
80
+ }
81
+ return this.depthStencilAttachment;
90
82
  }
91
-
92
- return this.depthStencilAttachment;
93
- }
94
-
95
83
  }
96
- //# sourceMappingURL=webgpu-canvas-context.js.map