@luma.gl/webgpu 9.0.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 (127) hide show
  1. package/README.md +1 -0
  2. package/dist/adapter/helpers/accessor-to-format.d.ts +1 -0
  3. package/dist/adapter/helpers/accessor-to-format.d.ts.map +1 -0
  4. package/dist/adapter/helpers/accessor-to-format.js +2 -0
  5. package/dist/adapter/helpers/accessor-to-format.js.map +1 -0
  6. package/dist/adapter/helpers/convert-texture-format.d.ts +5 -0
  7. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -0
  8. package/dist/adapter/helpers/convert-texture-format.js +8 -0
  9. package/dist/adapter/helpers/convert-texture-format.js.map +1 -0
  10. package/dist/adapter/helpers/generate-mipmaps.d.ts +10 -0
  11. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -0
  12. package/dist/adapter/helpers/generate-mipmaps.js +95 -0
  13. package/dist/adapter/helpers/generate-mipmaps.js.map +1 -0
  14. package/dist/adapter/helpers/get-bind-group.d.ts +13 -0
  15. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -0
  16. package/dist/adapter/helpers/get-bind-group.js +60 -0
  17. package/dist/adapter/helpers/get-bind-group.js.map +1 -0
  18. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +12 -0
  19. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -0
  20. package/dist/adapter/helpers/get-vertex-buffer-layout.js +98 -0
  21. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  22. package/dist/adapter/helpers/webgpu-parameters.d.ts +9 -0
  23. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -0
  24. package/dist/adapter/helpers/webgpu-parameters.js +134 -0
  25. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -0
  26. package/dist/adapter/resources/webgpu-buffer.d.ts +18 -0
  27. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -0
  28. package/dist/adapter/resources/webgpu-buffer.js +84 -0
  29. package/dist/adapter/resources/webgpu-buffer.js.map +1 -0
  30. package/dist/adapter/resources/webgpu-command-encoder.d.ts +45 -0
  31. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -0
  32. package/dist/adapter/resources/webgpu-command-encoder.js +66 -0
  33. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -0
  34. package/dist/adapter/resources/webgpu-compute-pass.d.ts +32 -0
  35. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -0
  36. package/dist/adapter/resources/webgpu-compute-pass.js +56 -0
  37. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -0
  38. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +12 -0
  39. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -0
  40. package/dist/adapter/resources/webgpu-compute-pipeline.js +27 -0
  41. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
  42. package/dist/adapter/resources/webgpu-external-texture.d.ts +18 -0
  43. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -0
  44. package/dist/adapter/resources/webgpu-external-texture.js +30 -0
  45. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -0
  46. package/dist/adapter/resources/webgpu-framebuffer.d.ts +29 -0
  47. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -0
  48. package/dist/adapter/resources/webgpu-framebuffer.js +111 -0
  49. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -0
  50. package/dist/adapter/resources/webgpu-query.d.ts +1 -0
  51. package/dist/adapter/resources/webgpu-query.d.ts.map +1 -0
  52. package/dist/adapter/resources/webgpu-query.js +2 -0
  53. package/dist/adapter/resources/webgpu-query.js.map +1 -0
  54. package/dist/adapter/resources/webgpu-render-pass.d.ts +34 -0
  55. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -0
  56. package/dist/adapter/resources/webgpu-render-pass.js +92 -0
  57. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -0
  58. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +41 -0
  59. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -0
  60. package/dist/adapter/resources/webgpu-render-pipeline.js +148 -0
  61. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -0
  62. package/dist/adapter/resources/webgpu-sampler.d.ts +16 -0
  63. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -0
  64. package/dist/adapter/resources/webgpu-sampler.js +19 -0
  65. package/dist/adapter/resources/webgpu-sampler.js.map +1 -0
  66. package/dist/adapter/resources/webgpu-shader.d.ts +21 -0
  67. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -0
  68. package/dist/adapter/resources/webgpu-shader.js +64 -0
  69. package/dist/adapter/resources/webgpu-shader.js.map +1 -0
  70. package/dist/adapter/resources/webgpu-texture.d.ts +39 -0
  71. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -0
  72. package/dist/adapter/resources/webgpu-texture.js +111 -0
  73. package/dist/adapter/resources/webgpu-texture.js.map +1 -0
  74. package/dist/adapter/webgpu-canvas-context.d.ts +32 -0
  75. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -0
  76. package/dist/adapter/webgpu-canvas-context.js +95 -0
  77. package/dist/adapter/webgpu-canvas-context.js.map +1 -0
  78. package/dist/adapter/webgpu-device.d.ts +67 -0
  79. package/dist/adapter/webgpu-device.d.ts.map +1 -0
  80. package/dist/adapter/webgpu-device.js +225 -0
  81. package/dist/adapter/webgpu-device.js.map +1 -0
  82. package/dist/adapter/webgpu-types.d.ts +1 -0
  83. package/dist/adapter/webgpu-types.d.ts.map +1 -0
  84. package/dist/adapter/webgpu-types.js +2 -0
  85. package/dist/adapter/webgpu-types.js.map +1 -0
  86. package/dist/bundle.d.ts +2 -0
  87. package/dist/bundle.d.ts.map +1 -0
  88. package/dist/bundle.js +5 -0
  89. package/dist/bundle.js.map +1 -0
  90. package/dist/glsl/glsllang.d.ts +3 -0
  91. package/dist/glsl/glsllang.d.ts.map +1 -0
  92. package/dist/glsl/glsllang.js +10 -0
  93. package/dist/glsl/glsllang.js.map +1 -0
  94. package/dist/index.d.ts +8 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +8 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/init.d.ts +2 -0
  99. package/dist/init.d.ts.map +1 -0
  100. package/dist/init.js +4 -0
  101. package/dist/init.js.map +1 -0
  102. package/package.json +36 -0
  103. package/src/adapter/helpers/accessor-to-format.ts +101 -0
  104. package/src/adapter/helpers/convert-texture-format.ts +10 -0
  105. package/src/adapter/helpers/generate-mipmaps.ts +107 -0
  106. package/src/adapter/helpers/get-bind-group.ts +82 -0
  107. package/src/adapter/helpers/get-vertex-buffer-layout.ts +123 -0
  108. package/src/adapter/helpers/webgpu-parameters.ts +226 -0
  109. package/src/adapter/resources/webgpu-buffer.ts +96 -0
  110. package/src/adapter/resources/webgpu-command-encoder.ts +111 -0
  111. package/src/adapter/resources/webgpu-compute-pass.ts +74 -0
  112. package/src/adapter/resources/webgpu-compute-pipeline.ts +34 -0
  113. package/src/adapter/resources/webgpu-external-texture.ts +37 -0
  114. package/src/adapter/resources/webgpu-framebuffer.ts +120 -0
  115. package/src/adapter/resources/webgpu-query.ts +43 -0
  116. package/src/adapter/resources/webgpu-render-pass.ts +128 -0
  117. package/src/adapter/resources/webgpu-render-pipeline.ts +231 -0
  118. package/src/adapter/resources/webgpu-sampler.ts +25 -0
  119. package/src/adapter/resources/webgpu-shader.ts +72 -0
  120. package/src/adapter/resources/webgpu-texture.ts +243 -0
  121. package/src/adapter/webgpu-canvas-context.ts +102 -0
  122. package/src/adapter/webgpu-device.ts +282 -0
  123. package/src/adapter/webgpu-types.ts +0 -0
  124. package/src/bundle.ts +4 -0
  125. package/src/glsl/glsllang.ts +14 -0
  126. package/src/index.ts +13 -0
  127. package/src/init.ts +4 -0
@@ -0,0 +1,111 @@
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';
5
+ const BASE_DIMENSIONS = {
6
+ '1d': '1d',
7
+ '2d': '2d',
8
+ '2d-array': '2d',
9
+ 'cube': '2d',
10
+ 'cube-array': '2d',
11
+ '3d': '3d'
12
+ };
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');
27
+ }
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
+ });
36
+ }
37
+
38
+ this.setSampler(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
+ }
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
+ }
111
+ //# sourceMappingURL=webgpu-texture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","format","Error","handle","createHandle","data","setData","setSampler","sampler","view","createView","width","height","createTexture","size","depthOrArrayLayers","depth","dimension","usage","mipLevelCount","mipLevels","sampleCount","samples","destroy","options","setImage","source","sourceX","sourceY","mipLevel","x","y","z","aspect","colorSpace","premultipliedAlpha","queue","copyExternalImageToTexture","origin","texture"],"mappings":";AACA,SAAQA,OAAR,QAAmE,cAAnE;AACA,SAAQC,sBAAR,QAAqC,mCAArC;AAEA,OAAOC,aAAP,MAA0B,kBAA1B;AAEA,MAAMC,eAAmD,GAAG;AAC1D,QAAM,IADoD;AAE1D,QAAM,IAFoD;AAG1D,cAAY,IAH8C;AAI1D,UAAQ,IAJkD;AAK1D,gBAAc,IAL4C;AAM1D,QAAM;AANoD,CAA5D;AASA,eAAe,MAAMC,aAAN,SAA4BJ,OAA5B,CAAoC;AAajDK,EAAAA,WAA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,SAAKzB,MAAL,CAAYI,MAAZ,CAAmBiC,KAAnB,CAAyBC,0BAAzB,CAEE;AACEX,MAAAA,MADF;AAEEY,MAAAA,MAAM,EAAE,CAACX,OAAD,EAAUC,OAAV;AAFV,KAFF,EAOE;AACEW,MAAAA,OAAO,EAAE,KAAKpC,MADhB;AAEEmC,MAAAA,MAAM,EAAE,CAACR,CAAD,EAAIC,CAAJ,EAAOC,CAAP,CAFV;AAGEH,MAAAA,QAHF;AAIEI,MAAAA,MAJF;AAKEC,MAAAA,UALF;AAMEC,MAAAA;AANF,KAPF,EAgBE,CACExB,KADF,EAEEC,MAFF,EAGEI,KAHF,CAhBF;AAsBA,WAAO,IAAP;AACD;;AAhJgD","sourcesContent":["// luma.gl, MIT license\nimport {Texture, TextureProps, Sampler, SamplerProps, assert} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport type WebGPUDevice from '../webgpu-device';\nimport WebGPUSampler from './webgpu-sampler';\n\nconst BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {\n '1d': '1d',\n '2d': '2d',\n '2d-array': '2d',\n 'cube': '2d',\n 'cube-array': '2d',\n '3d': '3d'\n};\n\nexport default class WebGPUTexture extends Texture {\n readonly device: WebGPUDevice;\n readonly handle: GPUTexture;\n readonly view: GPUTextureView;\n sampler: WebGPUSampler;\n\n // static async createFromImageURL(src, usage = 0) {\n // const img = document.createElement('img');\n // img.src = src;\n // await img.decode();\n // return WebGPUTexture(img, usage);\n // }\n\n constructor(device: WebGPUDevice, props: TextureProps) {\n super(device, props);\n\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n this.device = device;\n this.handle = this.props.handle || this.createHandle();\n\n if (this.props.data) {\n this.setData({data: this.props.data} );\n }\n\n // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture\n this.setSampler(props.sampler);\n\n // TODO - To support texture arrays we need to create custom views...\n // But we are not ready to expose TextureViews to the public API.\n this.view = this.handle.createView({\n // format: this.props.format,\n // dimension: this.props.dimension,\n // aspect = \"all\";\n // baseMipLevel: 0;\n // mipLevelCount;\n // baseArrayLayer = 0;\n // arrayLayerCount;\n });\n }\n\n protected createHandle(): GPUTexture {\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n // Deduce size from data - TODO this is a hack\n // @ts-expect-error\n const width = this.props.width || this.props.data?.width || 1;\n // @ts-expect-error\n const height = this.props.height || this.props.data?.height || 1;\n\n return this.device.handle.createTexture({\n size: {\n width,\n height,\n depthOrArrayLayers: this.props.depth\n },\n dimension: BASE_DIMENSIONS[this.props.dimension],\n format: getWebGPUTextureFormat(this.props.format),\n usage: this.props.usage,\n mipLevelCount: this.props.mipLevels,\n sampleCount: this.props.samples\n });\n }\n\n destroy(): void {\n this.handle.destroy();\n }\n\n /**\n * Set default sampler\n * Accept a sampler instance or set of props;\n */\n setSampler(sampler: Sampler | SamplerProps): this {\n this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);\n return this;\n }\n\n setData(options: {\n data: any;\n }) {\n return this.setImage({source: options.data});\n }\n\n /** Set image */\n setImage(options: {\n source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;\n width?: number;\n height?: number;\n depth?: number;\n sourceX?: number;\n sourceY?: number;\n mipLevel?: number;\n x?: number;\n y?: number;\n z?: number;\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n colorSpace?: 'srgb';\n premultipliedAlpha?: boolean;\n }): this {\n const {\n source,\n width = options.source.width,\n height = options.source.height,\n depth = 1,\n sourceX = 0,\n sourceY = 0,\n mipLevel = 0,\n x = 0,\n y = 0,\n z = 0,\n aspect = 'all',\n colorSpace = 'srgb',\n premultipliedAlpha = false\n } = options;\n\n // TODO - max out width\n\n this.device.handle.queue.copyExternalImageToTexture(\n // source: GPUImageCopyExternalImage\n {\n source,\n origin: [sourceX, sourceY]\n },\n // destination: GPUImageCopyTextureTagged\n {\n texture: this.handle,\n origin: [x, y, z],\n mipLevel,\n aspect,\n colorSpace,\n premultipliedAlpha\n },\n // copySize: GPUExtent3D\n [\n width,\n height,\n depth\n ]\n );\n return this;\n }\n\n /*\n async readPixels() {\n const readbackBuffer = device.createBuffer({\n usage: Buffer.COPY_DST | Buffer.MAP_READ,\n size: 4 * textureWidth * textureHeight,\n });\n\n // Copy data from the texture to the buffer.\n const encoder = device.createCommandEncoder();\n encoder.copyTextureToBuffer(\n { texture },\n { buffer, rowPitch: textureWidth * 4 },\n [textureWidth, textureHeight],\n );\n device.submit([encoder.finish()]);\n\n // Get the data on the CPU.\n await buffer.mapAsync(GPUMapMode.READ);\n saveScreenshot(buffer.getMappedRange());\n buffer.unmap();\n }\n\n setImageData(imageData, usage): this {\n let data = null;\n\n const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;\n if (bytesPerRow == img.width * 4) {\n data = imageData.data;\n } else {\n data = new Uint8Array(bytesPerRow * img.height);\n let imagePixelIndex = 0;\n for (let y = 0; y < img.height; ++y) {\n for (let x = 0; x < img.width; ++x) {\n const i = x * 4 + y * bytesPerRow;\n data[i] = imageData.data[imagePixelIndex];\n data[i + 1] = imageData.data[imagePixelIndex + 1];\n data[i + 2] = imageData.data[imagePixelIndex + 2];\n data[i + 3] = imageData.data[imagePixelIndex + 3];\n imagePixelIndex += 4;\n }\n }\n }\n return this;\n }\n\n setData(data): this {\n const textureDataBuffer = this.device.handle.createBuffer({\n size: data.byteLength,\n usage: Buffer.COPY_DST | Buffer.COPY_SRC,\n mappedAtCreation: true\n });\n new Uint8Array(textureDataBuffer.getMappedRange()).set(data);\n textureDataBuffer.unmap();\n\n this.setBuffer(textureDataBuffer);\n\n textureDataBuffer.destroy();\n return this;\n }\n\n setBuffer(textureDataBuffer, {bytesPerRow}): this {\n const commandEncoder = this.device.handle.createCommandEncoder();\n commandEncoder.copyBufferToTexture(\n {\n buffer: textureDataBuffer,\n bytesPerRow\n },\n {\n texture: this.handle\n },\n {\n width,\n height,\n depth\n }\n );\n\n this.device.handle.defaultQueue.submit([commandEncoder.finish()]);\n return this;\n }\n */\n}\n"],"file":"webgpu-texture.js"}
@@ -0,0 +1,32 @@
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';
6
+ /**
7
+ * Holds a WebGPU Canvas Context which handles resizing etc
8
+ */
9
+ export default class WebGPUCanvasContext extends CanvasContext {
10
+ readonly device: WebGPUDevice;
11
+ readonly gpuCanvasContext: GPUCanvasContext;
12
+ readonly format: TextureFormat;
13
+ width: number;
14
+ height: number;
15
+ depthStencilFormat: TextureFormat;
16
+ sampleCount: number;
17
+ private depthStencilAttachment;
18
+ constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps);
19
+ destroy(): void;
20
+ /** Update framebuffer with properly resized "swap chain" texture views */
21
+ getCurrentFramebuffer(): WEBGPUFramebuffer;
22
+ /** Resizes and updates render targets if necessary */
23
+ update(): void;
24
+ resize(options?: {
25
+ width?: number;
26
+ height?: number;
27
+ useDevicePixels?: boolean | number;
28
+ }): void;
29
+ /** We build render targets on demand (i.e. not when size changes but when about to render) */
30
+ _createDepthStencilAttachment(): Texture;
31
+ }
32
+ //# sourceMappingURL=webgpu-canvas-context.d.ts.map
@@ -0,0 +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,CAAU;gBAE5B,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAOhF,OAAO;IAIP,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"}
@@ -0,0 +1,95 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { CanvasContext, log } from '@luma.gl/api';
3
+ import { getWebGPUTextureFormat } from './helpers/convert-texture-format';
4
+ import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
5
+ 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, "width", -1);
16
+
17
+ _defineProperty(this, "height", -1);
18
+
19
+ _defineProperty(this, "depthStencilFormat", 'depth24plus');
20
+
21
+ _defineProperty(this, "sampleCount", 1);
22
+
23
+ _defineProperty(this, "depthStencilAttachment", void 0);
24
+
25
+ this.device = device;
26
+ this.gpuCanvasContext = this.canvas.getContext('webgpu');
27
+ this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
28
+ }
29
+
30
+ destroy() {
31
+ this.gpuCanvasContext.unconfigure();
32
+ }
33
+
34
+ getCurrentFramebuffer() {
35
+ this.update();
36
+ const currentColorAttachment = this.device.createTexture({
37
+ id: 'default-render-target',
38
+ handle: this.gpuCanvasContext.getCurrentTexture(),
39
+ format: this.format,
40
+ width: this.width,
41
+ height: this.height
42
+ });
43
+
44
+ this._createDepthStencilAttachment();
45
+
46
+ return new WEBGPUFramebuffer(this.device, {
47
+ colorAttachments: [currentColorAttachment],
48
+ depthStencilAttachment: this.depthStencilAttachment
49
+ });
50
+ }
51
+
52
+ update() {
53
+ const [width, height] = this.getPixelSize();
54
+ const sizeChanged = width !== this.width || height !== this.height;
55
+
56
+ if (sizeChanged) {
57
+ this.width = width;
58
+ this.height = height;
59
+
60
+ if (this.depthStencilAttachment) {
61
+ this.depthStencilAttachment.destroy();
62
+ this.depthStencilAttachment = undefined;
63
+ }
64
+
65
+ this.gpuCanvasContext.configure({
66
+ device: this.device.handle,
67
+ format: getWebGPUTextureFormat(this.format),
68
+ size: [this.width, this.height],
69
+ colorSpace: this.props.colorSpace,
70
+ compositingAlphaMode: this.props.compositingAlphaMode
71
+ });
72
+ log.log(1, "Resized to ".concat(this.width, "x").concat(this.height, "px"))();
73
+ }
74
+ }
75
+
76
+ resize(options) {
77
+ this.update();
78
+ }
79
+
80
+ _createDepthStencilAttachment() {
81
+ if (!this.depthStencilAttachment) {
82
+ this.depthStencilAttachment = this.device.createTexture({
83
+ id: 'depth-stencil-target',
84
+ format: this.depthStencilFormat,
85
+ width: this.width,
86
+ height: this.height,
87
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
88
+ });
89
+ }
90
+
91
+ return this.depthStencilAttachment;
92
+ }
93
+
94
+ }
95
+ //# sourceMappingURL=webgpu-canvas-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":["CanvasContext","log","getWebGPUTextureFormat","WEBGPUFramebuffer","WebGPUCanvasContext","constructor","device","adapter","props","gpuCanvasContext","canvas","getContext","format","getPreferredFormat","destroy","unconfigure","getCurrentFramebuffer","update","currentColorAttachment","createTexture","id","handle","getCurrentTexture","width","height","_createDepthStencilAttachment","colorAttachments","depthStencilAttachment","getPixelSize","sizeChanged","undefined","configure","size","colorSpace","compositingAlphaMode","resize","options","depthStencilFormat","usage","GPUTextureUsage","RENDER_ATTACHMENT"],"mappings":";AACA,SAAQA,aAAR,EAAuBC,GAAvB,QAAiC,cAAjC;AACA,SAAQC,sBAAR,QAAqC,kCAArC;AAEA,OAAOC,iBAAP,MAA8B,gCAA9B;AAKA,eAAe,MAAMC,mBAAN,SAAkCJ,aAAlC,CAAgD;AAW7DK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,OAAvB,EAA4CC,KAA5C,EAAuE;AAChF,UAAMA,KAAN;;AADgF;;AAAA;;AAAA;;AAAA,mCAPlE,CAAC,CAOiE;;AAAA,oCANjE,CAAC,CAMgE;;AAAA,gDAL9C,aAK8C;;AAAA,yCAJ5D,CAI4D;;AAAA;;AAEhF,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKG,gBAAL,GAAwB,KAAKC,MAAL,CAAYC,UAAZ,CAAuB,QAAvB,CAAxB;AACA,SAAKC,MAAL,GAAc,KAAKH,gBAAL,CAAsBI,kBAAtB,CAAyCN,OAAzC,CAAd;AACD;;AAEDO,EAAAA,OAAO,GAAG;AACR,SAAKL,gBAAL,CAAsBM,WAAtB;AACD;;AAGDC,EAAAA,qBAAqB,GAAsB;AAEzC,SAAKC,MAAL;AAGA,UAAMC,sBAAsB,GAAG,KAAKZ,MAAL,CAAYa,aAAZ,CAA0B;AACvDC,MAAAA,EAAE,EAAE,uBADmD;AAEvDC,MAAAA,MAAM,EAAE,KAAKZ,gBAAL,CAAsBa,iBAAtB,EAF+C;AAGvDV,MAAAA,MAAM,EAAE,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,6BAA6B,GAAG;AAC9B,QAAI,CAAC,KAAKE,sBAAV,EAAkC;AAChC,WAAKA,sBAAL,GAA8B,KAAKrB,MAAL,CAAYa,aAAZ,CAA0B;AACtDC,QAAAA,EAAE,EAAE,sBADkD;AAEtDR,QAAAA,MAAM,EAAE,KAAKyB,kBAFyC;AAGtDd,QAAAA,KAAK,EAAE,KAAKA,KAH0C;AAItDC,QAAAA,MAAM,EAAE,KAAKA,MAJyC;AAKtDc,QAAAA,KAAK,EAAEC,eAAe,CAACC;AAL+B,OAA1B,CAA9B;AAOD;;AACD,WAAO,KAAKb,sBAAZ;AACD;;AA3F4D","sourcesContent":["import type {Texture, TextureFormat, CanvasContextProps} from '@luma.gl/api';\nimport {CanvasContext, log} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from './helpers/convert-texture-format';\nimport WebGPUDevice from './webgpu-device';\nimport WEBGPUFramebuffer from './resources/webgpu-framebuffer';\n\n/** \n * Holds a WebGPU Canvas Context which handles resizing etc \n */\nexport default class WebGPUCanvasContext extends CanvasContext {\n readonly device: WebGPUDevice;\n readonly gpuCanvasContext: GPUCanvasContext;\n readonly format: TextureFormat;\n width: number = -1;\n height: number = -1;\n depthStencilFormat: TextureFormat = 'depth24plus';\n sampleCount: number = 1;\n\n private depthStencilAttachment: Texture;\n\n constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {\n super(props);\n this.device = device;\n this.gpuCanvasContext = this.canvas.getContext('webgpu') as GPUCanvasContext;\n this.format = this.gpuCanvasContext.getPreferredFormat(adapter);\n }\n\n destroy() {\n this.gpuCanvasContext.unconfigure();\n }\n\n /** Update framebuffer with properly resized \"swap chain\" texture views */\n getCurrentFramebuffer(): WEBGPUFramebuffer {\n // Ensure the canvas context size is updated\n this.update();\n\n // Wrap the current canvas context texture in a luma.gl texture \n const currentColorAttachment = this.device.createTexture({\n id: 'default-render-target',\n handle: this.gpuCanvasContext.getCurrentTexture(),\n format: this.format,\n width: this.width,\n height: this.height\n });\n\n // Resize the depth stencil attachment\n this._createDepthStencilAttachment();\n\n return new WEBGPUFramebuffer(this.device, {\n colorAttachments: [currentColorAttachment],\n depthStencilAttachment: this.depthStencilAttachment\n });\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const [width, height] = this.getPixelSize();\n\n const sizeChanged = width !== this.width || height !== this.height;\n\n if (sizeChanged) {\n this.width = width;\n this.height = height;\n\n if (this.depthStencilAttachment) {\n this.depthStencilAttachment.destroy();\n this.depthStencilAttachment = undefined;\n }\n\n // Reconfigure the canvas size.\n // https://www.w3.org/TR/webgpu/#canvas-configuration\n this.gpuCanvasContext.configure({\n device: this.device.handle,\n format: getWebGPUTextureFormat(this.format),\n size: [this.width, this.height],\n colorSpace: this.props.colorSpace,\n compositingAlphaMode: this.props.compositingAlphaMode\n });\n\n log.log(1, `Resized to ${this.width}x${this.height}px`)();\n }\n\n }\n\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n this.update();\n }\n\n /** We build render targets on demand (i.e. not when size changes but when about to render) */\n _createDepthStencilAttachment() {\n if (!this.depthStencilAttachment) {\n this.depthStencilAttachment = this.device.createTexture({\n id: 'depth-stencil-target',\n format: this.depthStencilFormat,\n width: this.width,\n height: this.height,\n usage: GPUTextureUsage.RENDER_ATTACHMENT\n });\n }\n return this.depthStencilAttachment;\n }\n}\n"],"file":"webgpu-canvas-context.js"}
@@ -0,0 +1,67 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import type { DeviceProps, DeviceInfo, DeviceLimits, DeviceFeature, CanvasContextProps, BufferProps, SamplerProps, ShaderProps, TextureProps, TextureFormat, ExternalTextureProps, FramebufferProps, RenderPipelineProps, ComputePipelineProps, RenderPassProps, ComputePassProps } from '@luma.gl/api';
3
+ import { Device } from '@luma.gl/api';
4
+ import WebGPUBuffer from './resources/webgpu-buffer';
5
+ import WebGPUTexture from './resources/webgpu-texture';
6
+ import WebGPUExternalTexture from './resources/webgpu-external-texture';
7
+ import WebGPUSampler from './resources/webgpu-sampler';
8
+ import WebGPUShader from './resources/webgpu-shader';
9
+ import WebGPURenderPipeline from './resources/webgpu-render-pipeline';
10
+ import WebGPUFramebuffer from './resources/webgpu-framebuffer';
11
+ import WebGPUComputePipeline from './resources/webgpu-compute-pipeline';
12
+ import WebGPURenderPass from './resources/webgpu-render-pass';
13
+ import WebGPUComputePass from './resources/webgpu-compute-pass';
14
+ import WebGPUCanvasContext from './webgpu-canvas-context';
15
+ /** WebGPU Device implementation */
16
+ export default class WebGPUDevice extends Device {
17
+ readonly handle: GPUDevice;
18
+ readonly adapter: GPUAdapter;
19
+ readonly lost: Promise<{
20
+ reason: 'destroyed';
21
+ message: string;
22
+ }>;
23
+ canvasContext: WebGPUCanvasContext | undefined;
24
+ commandEncoder: GPUCommandEncoder;
25
+ renderPass: WebGPURenderPass;
26
+ private _info;
27
+ private _isLost;
28
+ static type: string;
29
+ /** Check if WebGPU is available */
30
+ static isSupported(): boolean;
31
+ static create(props: DeviceProps): Promise<WebGPUDevice>;
32
+ constructor(device: GPUDevice, adapter: GPUAdapter, props: DeviceProps);
33
+ destroy(): void;
34
+ get info(): DeviceInfo;
35
+ features: Set<DeviceFeature>;
36
+ get limits(): DeviceLimits;
37
+ isTextureFormatSupported(format: TextureFormat): boolean;
38
+ /** @todo implement proper check? */
39
+ isTextureFormatFilterable(format: TextureFormat): boolean;
40
+ /** @todo implement proper check? */
41
+ isTextureFormatRenderable(format: TextureFormat): boolean;
42
+ get isLost(): boolean;
43
+ _createBuffer(props: BufferProps): WebGPUBuffer;
44
+ _createTexture(props: TextureProps): WebGPUTexture;
45
+ createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture;
46
+ createShader(props: ShaderProps): WebGPUShader;
47
+ createSampler(props: SamplerProps): WebGPUSampler;
48
+ createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline;
49
+ createFramebuffer(props: FramebufferProps): WebGPUFramebuffer;
50
+ createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline;
51
+ /**
52
+ * Allows a render pass to begin against a canvas context
53
+ * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
54
+ */
55
+ beginRenderPass(props?: RenderPassProps): WebGPURenderPass;
56
+ beginComputePass(props?: ComputePassProps): WebGPUComputePass;
57
+ createCanvasContext(props?: CanvasContextProps): WebGPUCanvasContext;
58
+ /**
59
+ * Gets default renderpass encoder.
60
+ * Creates a new encoder against default canvasContext if not already created
61
+ * @note Called internally by Model.
62
+ */
63
+ getDefaultRenderPass(): WebGPURenderPass;
64
+ submit(): void;
65
+ _getFeatures(): Set<DeviceFeature>;
66
+ }
67
+ //# sourceMappingURL=webgpu-device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-device.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,MAAM,EAA2B,MAAM,cAAc,CAAC;AAC9D,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,qBAAqB,MAAM,qCAAqC,CAAC;AACxE,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,oBAAoB,MAAM,oCAAoC,CAAC;AACtE,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAO,qBAAqB,MAAM,qCAAqC,CAAC;AACxE,OAAO,gBAAgB,MAAM,gCAAgC,CAAC;AAC9D,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAEhE,OAAO,mB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E,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY;IAI9C,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa;IAIjD,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB;IAItE,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB;IAI7D,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB;IAMzE;;;OAGG;IACH,eAAe,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB;IAK1D,gBAAgB,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;IAK7D,mBAAmB,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,mBAAmB;IAIpE;;;;OAIG;IACH,oBAAoB,IAAI,gBAAgB;IAOxC,MAAM,IAAI,IAAI;IAQd,YAAY;CAsDb"}
@@ -0,0 +1,225 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { Device, CanvasContext, log } from '@luma.gl/api';
3
+ import WebGPUBuffer from './resources/webgpu-buffer';
4
+ import WebGPUTexture from './resources/webgpu-texture';
5
+ import WebGPUExternalTexture from './resources/webgpu-external-texture';
6
+ import WebGPUSampler from './resources/webgpu-sampler';
7
+ import WebGPUShader from './resources/webgpu-shader';
8
+ import WebGPURenderPipeline from './resources/webgpu-render-pipeline';
9
+ import WebGPUComputePipeline from './resources/webgpu-compute-pipeline';
10
+ import WebGPURenderPass from './resources/webgpu-render-pass';
11
+ import WebGPUComputePass from './resources/webgpu-compute-pass';
12
+ import WebGPUCanvasContext from './webgpu-canvas-context';
13
+ export default class WebGPUDevice extends Device {
14
+ static isSupported() {
15
+ return Boolean(typeof navigator !== 'undefined' && navigator.gpu);
16
+ }
17
+
18
+ static async create(props) {
19
+ if (!navigator.gpu) {
20
+ throw new Error('WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu');
21
+ }
22
+
23
+ log.groupCollapsed(1, 'WebGPUDevice created')();
24
+ const adapter = await navigator.gpu.requestAdapter({
25
+ powerPreference: "high-performance"
26
+ });
27
+ log.probe(1, "Adapter available")();
28
+ const gpuDevice = await adapter.requestDevice({
29
+ requiredFeatures: adapter.features
30
+ });
31
+ log.probe(1, "GPUDevice available")();
32
+
33
+ if (typeof props.canvas === 'string') {
34
+ await CanvasContext.pageLoaded;
35
+ log.probe(1, "DOM is loaded")();
36
+ }
37
+
38
+ const device = new WebGPUDevice(gpuDevice, adapter, props);
39
+ log.probe(1, "Device created", device.info)();
40
+ log.table(1, device.info)();
41
+ log.groupEnd(1)();
42
+ return device;
43
+ }
44
+
45
+ constructor(device, adapter, props) {
46
+ super(props);
47
+
48
+ _defineProperty(this, "handle", void 0);
49
+
50
+ _defineProperty(this, "adapter", void 0);
51
+
52
+ _defineProperty(this, "lost", void 0);
53
+
54
+ _defineProperty(this, "canvasContext", void 0);
55
+
56
+ _defineProperty(this, "commandEncoder", void 0);
57
+
58
+ _defineProperty(this, "renderPass", void 0);
59
+
60
+ _defineProperty(this, "_info", void 0);
61
+
62
+ _defineProperty(this, "_isLost", false);
63
+
64
+ _defineProperty(this, "features", void 0);
65
+
66
+ this.handle = device;
67
+ this.adapter = adapter;
68
+ this._info = {
69
+ type: 'webgpu',
70
+ vendor: this.adapter.name,
71
+ renderer: '',
72
+ version: '',
73
+ gpu: 'unknown',
74
+ shadingLanguages: ['glsl', 'wgsl'],
75
+ shadingLanguageVersions: {
76
+ glsl: '450',
77
+ wgsl: '100'
78
+ },
79
+ vendorMasked: '',
80
+ rendererMasked: ''
81
+ };
82
+ this.lost = this.handle.lost;
83
+ this.lost.then(_ => {
84
+ this._isLost = true;
85
+ });
86
+
87
+ if (props.canvas) {
88
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
89
+ canvas: props.canvas
90
+ });
91
+ }
92
+
93
+ this.features = this._getFeatures();
94
+ }
95
+
96
+ destroy() {
97
+ this.handle.destroy();
98
+ }
99
+
100
+ get info() {
101
+ return this._info;
102
+ }
103
+
104
+ get limits() {
105
+ return this.handle.limits;
106
+ }
107
+
108
+ isTextureFormatSupported(format) {
109
+ return !format.includes('webgl');
110
+ }
111
+
112
+ isTextureFormatFilterable(format) {
113
+ return this.isTextureFormatSupported(format);
114
+ }
115
+
116
+ isTextureFormatRenderable(format) {
117
+ return this.isTextureFormatSupported(format);
118
+ }
119
+
120
+ get isLost() {
121
+ return this._isLost;
122
+ }
123
+
124
+ _createBuffer(props) {
125
+ return new WebGPUBuffer(this, props);
126
+ }
127
+
128
+ _createTexture(props) {
129
+ return new WebGPUTexture(this, props);
130
+ }
131
+
132
+ createExternalTexture(props) {
133
+ return new WebGPUExternalTexture(this, props);
134
+ }
135
+
136
+ createShader(props) {
137
+ return new WebGPUShader(this, props);
138
+ }
139
+
140
+ createSampler(props) {
141
+ return new WebGPUSampler(this, props);
142
+ }
143
+
144
+ createRenderPipeline(props) {
145
+ return new WebGPURenderPipeline(this, props);
146
+ }
147
+
148
+ createFramebuffer(props) {
149
+ throw new Error('Not implemented');
150
+ }
151
+
152
+ createComputePipeline(props) {
153
+ return new WebGPUComputePipeline(this, props);
154
+ }
155
+
156
+ beginRenderPass(props) {
157
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
158
+ return new WebGPURenderPass(this, props);
159
+ }
160
+
161
+ beginComputePass(props) {
162
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
163
+ return new WebGPUComputePass(this, props);
164
+ }
165
+
166
+ createCanvasContext(props) {
167
+ return new WebGPUCanvasContext(this, this.adapter, props);
168
+ }
169
+
170
+ getDefaultRenderPass() {
171
+ this.renderPass = this.renderPass || this.beginRenderPass({
172
+ framebuffer: this.canvasContext.getCurrentFramebuffer()
173
+ });
174
+ return this.renderPass;
175
+ }
176
+
177
+ submit() {
178
+ this.renderPass.endPass();
179
+ const commandBuffer = this.commandEncoder.finish();
180
+ this.handle.queue.submit([commandBuffer]);
181
+ this.commandEncoder = null;
182
+ this.renderPass = null;
183
+ }
184
+
185
+ _getFeatures() {
186
+ const features = new Set(this.handle.features);
187
+
188
+ if (features.has('depth-clamping')) {
189
+ features.delete('depth-clamping');
190
+ features.add('depth-clip-control');
191
+ }
192
+
193
+ if (features.has('texture-compression-bc')) {
194
+ features.add('texture-compression-bc5-webgl');
195
+ }
196
+
197
+ features.add('webgpu');
198
+ features.add('timer-query-webgl');
199
+ features.add('vertex-array-object-webgl1');
200
+ features.add('instanced-rendering-webgl1');
201
+ features.add('multiple-render-targets-webgl1');
202
+ features.add('index-uint32-webgl1');
203
+ features.add('blend-minmax-webgl1');
204
+ features.add('texture-blend-float-webgl1');
205
+ features.add('texture-formats-srgb-webgl1');
206
+ features.add('texture-formats-depth-webgl1');
207
+ features.add('texture-formats-float32-webgl1');
208
+ features.add('texture-formats-float16-webgl1');
209
+ features.add('texture-filter-linear-float32-webgl');
210
+ features.add('texture-filter-linear-float16-webgl');
211
+ features.add('texture-filter-anisotropic-webgl');
212
+ features.add('texture-renderable-rgba32float-webgl');
213
+ features.add('texture-renderable-float32-webgl');
214
+ features.add('texture-renderable-float16-webgl');
215
+ features.add('glsl-frag-data');
216
+ features.add('glsl-frag-depth');
217
+ features.add('glsl-derivatives');
218
+ features.add('glsl-texture-lod');
219
+ return features;
220
+ }
221
+
222
+ }
223
+
224
+ _defineProperty(WebGPUDevice, "type", 'webgpu');
225
+ //# sourceMappingURL=webgpu-device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapter/webgpu-device.ts"],"names":["Device","CanvasContext","log","WebGPUBuffer","WebGPUTexture","WebGPUExternalTexture","WebGPUSampler","WebGPUShader","WebGPURenderPipeline","WebGPUComputePipeline","WebGPURenderPass","WebGPUComputePass","WebGPUCanvasContext","WebGPUDevice","isSupported","Boolean","navigator","gpu","create","props","Error","groupCollapsed","adapter","requestAdapter","powerPreference","probe","gpuDevice","requestDevice","requiredFeatures","features","canvas","pageLoaded","device","info","table","groupEnd","constructor","handle","_info","type","vendor","name","renderer","version","shadingLanguages","shadingLanguageVersions","glsl","wgsl","vendorMasked","rendererMasked","lost","then","_","_isLost","canvasContext","_getFeatures","destroy","limits","isTextureFormatSupported","format","includes","isTextureFormatFilterable","isTextureFormatRenderable","isLost","_createBuffer","_createTexture","createExternalTexture","createShader","createSampler","createRenderPipeline","createFramebuffer","createComputePipeline","beginRenderPass","commandEncoder","createCommandEncoder","beginComputePass","createCanvasContext","getDefaultRenderPass","renderPass","framebuffer","getCurrentFramebuffer","submit","endPass","commandBuffer","finish","queue","Set","has","delete","add"],"mappings":";AAoBA,SAAQA,MAAR,EAAgBC,aAAhB,EAA+BC,GAA/B,QAA+C,cAA/C;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,oBAAP,MAAiC,oCAAjC;AAEA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,gBAAP,MAA6B,gCAA7B;AACA,OAAOC,iBAAP,MAA8B,iCAA9B;AAEA,OAAOC,mBAAP,MAAgC,yBAAhC;AAIA,eAAe,MAAMC,YAAN,SAA2Bb,MAA3B,CAAkC;AAe7B,SAAXc,WAAW,GAAY;AAC5B,WAAOC,OAAO,CAAC,OAAOC,SAAP,KAAqB,WAArB,IAAoCA,SAAS,CAACC,GAA/C,CAAd;AACD;;AAEkB,eAANC,MAAM,CAACC,KAAD,EAA4C;AAC7D,QAAI,CAACH,SAAS,CAACC,GAAf,EAAoB;AAClB,YAAM,IAAIG,KAAJ,CAAU,8FAAV,CAAN;AACD;;AACDlB,IAAAA,GAAG,CAACmB,cAAJ,CAAmB,CAAnB,EAAsB,sBAAtB;AACA,UAAMC,OAAO,GAAG,MAAMN,SAAS,CAACC,GAAV,CAAcM,cAAd,CAA6B;AACjDC,MAAAA,eAAe,EAAE;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Ab;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,qBAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,qBAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,4BAAb;AAGA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,6BAAb;AAGA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,8BAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,gCAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,gCAAb;AAEA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,qCAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,qCAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,kCAAb;AAGA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,sCAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,kCAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,kCAAb;AAGA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,gBAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,iBAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,kBAAb;AACA5D,IAAAA,QAAQ,CAAC4D,GAAT,CAAa,kBAAb;AAEA,WAAO5D,QAAP;AACD;;AApP8C;;gBAA5BhB,Y,UAYG,Q","sourcesContent":["/// <reference types=\"@webgpu/types\" />\n\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n BufferProps,\n SamplerProps,\n ShaderProps,\n TextureProps,\n TextureFormat,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipelineProps,\n ComputePipelineProps,\n RenderPassProps,\n ComputePassProps\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, cast} from '@luma.gl/api';\nimport WebGPUBuffer from './resources/webgpu-buffer';\nimport WebGPUTexture from './resources/webgpu-texture';\nimport WebGPUExternalTexture from './resources/webgpu-external-texture';\nimport WebGPUSampler from './resources/webgpu-sampler';\nimport WebGPUShader from './resources/webgpu-shader';\nimport WebGPURenderPipeline from './resources/webgpu-render-pipeline';\nimport WebGPUFramebuffer from './resources/webgpu-framebuffer';\nimport WebGPUComputePipeline from './resources/webgpu-compute-pipeline';\nimport WebGPURenderPass from './resources/webgpu-render-pass';\nimport WebGPUComputePass from './resources/webgpu-compute-pass';\n\nimport WebGPUCanvasContext from './webgpu-canvas-context';\n// import {loadGlslangModule} from '../glsl/glslang';\n\n/** WebGPU Device implementation */\nexport default class WebGPUDevice extends Device {\n readonly handle: GPUDevice;\n readonly adapter: GPUAdapter;\n readonly lost: Promise<{reason: 'destroyed', message: string}>;\n canvasContext: WebGPUCanvasContext | undefined;\n\n commandEncoder: GPUCommandEncoder;\n renderPass: WebGPURenderPass;\n\n private _info: DeviceInfo;\n private _isLost: boolean = false;\n\n static type: string = 'webgpu';\n\n /** Check if WebGPU is available */\n static isSupported(): boolean {\n return Boolean(typeof navigator !== 'undefined' && navigator.gpu);\n }\n\n static async create(props: DeviceProps): Promise<WebGPUDevice> {\n if (!navigator.gpu) {\n throw new Error('WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu');\n }\n log.groupCollapsed(1, 'WebGPUDevice created')();\n const adapter = await navigator.gpu.requestAdapter({\n powerPreference: \"high-performance\"\n // forceSoftware: false\n });\n log.probe(1, \"Adapter available\")();\n\n const gpuDevice = await adapter.requestDevice({\n requiredFeatures: adapter.features as ReadonlySet<GPUFeatureName>,\n // TODO ensure we obtain best limits\n // requiredLimits: adapter.limits\n });\n log.probe(1, \"GPUDevice available\")();\n\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n log.probe(1, \"DOM is loaded\")();\n }\n\n const device = new WebGPUDevice(gpuDevice, adapter, props);\n log.probe(1, \"Device created\", device.info)();\n log.table(1, device.info)();\n log.groupEnd(1)();\n return device;\n }\n\n constructor(device: GPUDevice, adapter: GPUAdapter, props: DeviceProps) {\n super(props);\n this.handle = device;\n this.adapter = adapter;\n\n this._info = {\n type: 'webgpu',\n vendor: this.adapter.name,\n renderer: '',\n version: '',\n gpu: 'unknown', // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',\n shadingLanguages: ['glsl', 'wgsl'],\n shadingLanguageVersions: {\n glsl: '450',\n wgsl: '100'\n },\n vendorMasked: '',\n rendererMasked: ''\n };\n\n this.lost = this.handle.lost;\n this.lost.then(_ => {\n this._isLost = true;\n });\n\n // Note: WebGPU devices can be created without a canvas, for compute shader purposes\n if (props.canvas) {\n this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {canvas: props.canvas});\n }\n\n this.features = this._getFeatures();\n }\n\n // TODO\n // Load the glslang module now so that it is available synchronously when compiling shaders\n // const {glsl = true} = props;\n // this.glslang = glsl && await loadGlslangModule();\n\n destroy() {\n this.handle.destroy();\n }\n\n get info(): DeviceInfo {\n return this._info;\n }\n\n features: Set<DeviceFeature>;\n\n get limits(): DeviceLimits {\n return this.handle.limits;\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return !format.includes('webgl');\n }\n\n /** @todo implement proper check? */\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format); \n }\n\n /** @todo implement proper check? */\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format); \n }\n\n get isLost(): boolean {\n return this._isLost;\n }\n\n _createBuffer(props: BufferProps): WebGPUBuffer {\n return new WebGPUBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WebGPUTexture {\n return new WebGPUTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture {\n return new WebGPUExternalTexture(this, props);\n }\n\n createShader(props: ShaderProps): WebGPUShader {\n return new WebGPUShader(this, props);\n }\n\n createSampler(props: SamplerProps): WebGPUSampler {\n return new WebGPUSampler(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline {\n return new WebGPURenderPipeline(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WebGPUFramebuffer {\n throw new Error('Not implemented');\n }\n\n createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline {\n return new WebGPUComputePipeline(this, props);\n }\n\n // WebGPU specifics\n\n /** \n * Allows a render pass to begin against a canvas context\n * @todo need to support a \"Framebuffer\" equivalent (aka preconfigured RenderPassDescriptors?).\n */\n beginRenderPass(props?: RenderPassProps): WebGPURenderPass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPURenderPass(this, props);\n }\n\n beginComputePass(props?: ComputePassProps): WebGPUComputePass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPUComputePass(this, props);\n }\n\n createCanvasContext(props?: CanvasContextProps): WebGPUCanvasContext {\n return new WebGPUCanvasContext(this, this.adapter, props);\n }\n\n /** \n * Gets default renderpass encoder.\n * Creates a new encoder against default canvasContext if not already created \n * @note Called internally by Model.\n */\n getDefaultRenderPass(): WebGPURenderPass {\n this.renderPass = this.renderPass || this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n submit(): void {\n this.renderPass.endPass();\n const commandBuffer = this.commandEncoder.finish();\n this.handle.queue.submit([commandBuffer]);\n this.commandEncoder = null;\n this.renderPass = null;\n }\n\n _getFeatures() {\n // WebGPU Features\n const features = new Set<DeviceFeature>(this.handle.features as Set<DeviceFeature>);\n\n // Fixups for pre-standard names: https://github.com/webgpu-native/webgpu-headers/issues/133\n // @ts-expect-error Chrome Canary v99\n if (features.has('depth-clamping')) {\n // @ts-expect-error Chrome Canary v99\n features.delete('depth-clamping');\n features.add('depth-clip-control');\n }\n\n // Add subsets\n if (features.has('texture-compression-bc')) {\n features.add('texture-compression-bc5-webgl');\n }\n\n features.add('webgpu');\n\n features.add('timer-query-webgl');\n\n // WEBGL1 SUPPORT\n features.add('vertex-array-object-webgl1');\n features.add('instanced-rendering-webgl1');\n features.add('multiple-render-targets-webgl1');\n features.add('index-uint32-webgl1');\n features.add('blend-minmax-webgl1');\n features.add('texture-blend-float-webgl1');\n \n // TEXTURES, RENDERBUFFERS\n features.add('texture-formats-srgb-webgl1');\n \n // TEXTURES\n features.add('texture-formats-depth-webgl1');\n features.add('texture-formats-float32-webgl1');\n features.add('texture-formats-float16-webgl1');\n \n features.add('texture-filter-linear-float32-webgl');\n features.add('texture-filter-linear-float16-webgl');\n features.add('texture-filter-anisotropic-webgl');\n \n // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS\n features.add('texture-renderable-rgba32float-webgl');\n features.add('texture-renderable-float32-webgl');\n features.add('texture-renderable-float16-webgl');\n \n // GLSL extensions\n features.add('glsl-frag-data');\n features.add('glsl-frag-depth');\n features.add('glsl-derivatives');\n features.add('glsl-texture-lod');\n\n return features;\n }\n}\n"],"file":"webgpu-device.js"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=webgpu-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu-types.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=webgpu-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"webgpu-types.js"}
@@ -0,0 +1,2 @@
1
+ declare const moduleExports: any;
2
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
package/dist/bundle.js ADDED
@@ -0,0 +1,5 @@
1
+ const moduleExports = require('./index');
2
+
3
+ globalThis.luma = globalThis.luma || {};
4
+ module.exports = Object.assign(globalThis.luma, moduleExports);
5
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","luma","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,IAAX,GAAkBD,UAAU,CAACC,IAAX,IAAmB,EAArC;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,IAAzB,EAA+BH,aAA/B,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.luma = globalThis.luma || {};\nmodule.exports = Object.assign(globalThis.luma, moduleExports);\n"],"file":"bundle.js"}