@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,164 +1,167 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { RenderPipeline, cast, log, isObjectEmpty } from '@luma.gl/api';
3
- import { applyParametersToRenderPipelineDescriptor } from '../helpers/webgpu-parameters';
4
- import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
5
- import { getBindGroup } from '../helpers/get-bind-group';
6
- import { getVertexBufferLayout, getBufferSlots } from '../helpers/get-vertex-buffer-layout';
7
- export default class WebGPURenderPipeline extends RenderPipeline {
8
- constructor(device, props) {
9
- super(device, props);
10
-
11
- _defineProperty(this, "device", void 0);
12
-
13
- _defineProperty(this, "handle", void 0);
14
-
15
- _defineProperty(this, "vs", void 0);
16
-
17
- _defineProperty(this, "fs", null);
18
-
19
- _defineProperty(this, "_bufferSlots", void 0);
20
-
21
- _defineProperty(this, "_buffers", void 0);
22
-
23
- _defineProperty(this, "_indexBuffer", null);
24
-
25
- _defineProperty(this, "_bindGroupLayout", void 0);
26
-
27
- _defineProperty(this, "_bindGroup", null);
28
-
29
- this.device = device;
30
- this.handle = this.props.handle || this.createHandle();
31
- this.handle.label = this.props.id;
32
- this.vs = cast(props.vs);
33
- this.fs = cast(props.fs);
34
- this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);
35
- this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);
36
- this._bindGroupLayout = this.handle.getBindGroupLayout(0);
37
- }
38
-
39
- createHandle() {
40
- const descriptor = this._getRenderPipelineDescriptor();
41
-
42
- const renderPipeline = this.device.handle.createRenderPipeline(descriptor);
43
- log.groupCollapsed(1, "new WebGPRenderPipeline(".concat(this.id, ")"))();
44
- log.log(1, JSON.stringify(descriptor, null, 2))();
45
- log.groupEnd(1)();
46
- return renderPipeline;
47
- }
48
-
49
- destroy() {}
50
-
51
- setIndexBuffer(indexBuffer) {
52
- this._indexBuffer = cast(indexBuffer);
53
- }
54
-
55
- setAttributes(attributes) {
56
- for (const [name, buffer] of Object.entries(attributes)) {
57
- const bufferIndex = this._bufferSlots[name];
58
-
59
- if (bufferIndex >= 0) {
60
- this._buffers[bufferIndex] = buffer;
61
- } else {
62
- throw new Error("Setting attribute '".concat(name, "' not listed in shader layout for program ").concat(this.id));
63
- }
1
+ // luma.gl MIT license
2
+ import { RenderPipeline, cast, log } from '@luma.gl/core';
3
+ import { applyParametersToRenderPipelineDescriptor } from "../helpers/webgpu-parameters.js";
4
+ import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
5
+ import { getBindGroup } from "../helpers/get-bind-group.js";
6
+ import { getVertexBufferLayout } from "../helpers/get-vertex-buffer-layout.js";
7
+ // RENDER PIPELINE
8
+ /** Creates a new render pipeline when parameters change */
9
+ export class WebGPURenderPipeline extends RenderPipeline {
10
+ device;
11
+ handle;
12
+ vs;
13
+ fs = null;
14
+ /** For internal use to create BindGroups */
15
+ _bindings;
16
+ _bindGroupLayout = null;
17
+ _bindGroup = null;
18
+ constructor(device, props) {
19
+ super(device, props);
20
+ this.device = device;
21
+ this.handle = this.props.handle;
22
+ if (!this.handle) {
23
+ const descriptor = this._getRenderPipelineDescriptor();
24
+ log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
25
+ log.probe(1, JSON.stringify(descriptor, null, 2))();
26
+ log.groupEnd(1)();
27
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
28
+ }
29
+ this.handle.label = this.props.id;
30
+ this.vs = cast(props.vs);
31
+ this.fs = cast(props.fs);
32
+ this._bindings = { ...this.props.bindings };
64
33
  }
65
- }
66
-
67
- setBindings(bindings) {
68
- if (!isObjectEmpty(this.props.bindings)) {
69
- Object.assign(this.props.bindings, bindings);
70
- this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.layout, this.props.bindings);
34
+ destroy() {
35
+ // WebGPURenderPipeline has no destroy method.
36
+ this.handle = null;
71
37
  }
72
- }
73
-
74
- setUniforms(uniforms) {
75
- if (!isObjectEmpty(uniforms)) {
76
- throw new Error('WebGPU does not support uniforms');
38
+ /**
39
+ * @todo Use renderpass.setBindings() ?
40
+ * @todo Do we want to expose BindGroups in the API and remove this?
41
+ */
42
+ setBindings(bindings) {
43
+ Object.assign(this._bindings, bindings);
77
44
  }
78
- }
79
-
80
- _getBuffers() {
81
- return this._buffers;
82
- }
83
-
84
- _getBindGroup() {
85
- return this._bindGroup;
86
- }
87
-
88
- _getRenderPipelineDescriptor() {
89
- const vertex = {
90
- module: cast(this.props.vs).handle,
91
- entryPoint: this.props.vsEntryPoint || 'main',
92
- buffers: getVertexBufferLayout(this.props.layout, this.props.bufferMap)
93
- };
94
- let fragment;
95
-
96
- if (this.props.fs) {
97
- var _this$device, _this$device$canvasCo;
98
-
99
- fragment = {
100
- module: cast(this.props.fs).handle,
101
- entryPoint: this.props.fsEntryPoint || 'main',
102
- targets: [{
103
- format: getWebGPUTextureFormat((_this$device = this.device) === null || _this$device === void 0 ? void 0 : (_this$device$canvasCo = _this$device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.format)
104
- }]
105
- };
45
+ /** @todo - should this be moved to renderpass? */
46
+ draw(options) {
47
+ const webgpuRenderPass = options.renderPass;
48
+ // Set pipeline
49
+ webgpuRenderPass.handle.setPipeline(this.handle);
50
+ // Set bindings (uniform buffers, textures etc)
51
+ const bindGroup = this._getBindGroup();
52
+ if (bindGroup) {
53
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
54
+ }
55
+ // Set attributes
56
+ // Note: Rebinds constant attributes before each draw call
57
+ options.vertexArray.bindBeforeRender(options.renderPass);
58
+ // Draw
59
+ if (options.indexCount) {
60
+ webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
61
+ }
62
+ else {
63
+ webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, // If 0, nothing will be drawn
64
+ options.firstInstance);
65
+ }
66
+ // Note: Rebinds constant attributes before each draw call
67
+ options.vertexArray.unbindAfterRender(options.renderPass);
68
+ return true;
106
69
  }
107
-
108
- switch (this.props.topology) {
109
- case 'triangle-fan':
110
- case 'line-loop':
111
- throw new Error("WebGPU does not support primitive topology ".concat(this.props.topology));
112
-
113
- default:
70
+ /** Return a bind group created by setBindings */
71
+ _getBindGroup() {
72
+ if (this.props.shaderLayout.bindings.length === 0) {
73
+ return null;
74
+ }
75
+ // Get hold of the bind group layout. We don't want to do this unless we know there is at least one bind group
76
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
77
+ // Set up the bindings
78
+ // TODO what if bindings change? We need to rebuild the bind group!
79
+ this._bindGroup =
80
+ this._bindGroup ||
81
+ getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this._bindings);
82
+ return this._bindGroup;
114
83
  }
115
-
116
- let descriptor = {
117
- vertex,
118
- fragment,
119
- primitive: {
120
- topology: this.props.topology
121
- }
122
- };
123
- applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
124
- return descriptor;
125
- }
126
-
127
- draw(options) {
128
- const webgpuRenderPass = cast(options.renderPass) || this.device.getDefaultRenderPass();
129
- webgpuRenderPass.handle.setPipeline(this.handle);
130
-
131
- if (this._getBindGroup()) {
132
- webgpuRenderPass.handle.setBindGroup(0, this._getBindGroup());
84
+ /**
85
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
86
+ */
87
+ _getRenderPipelineDescriptor() {
88
+ // Set up the vertex stage
89
+ const vertex = {
90
+ module: cast(this.props.vs).handle,
91
+ entryPoint: this.props.vertexEntryPoint || 'main',
92
+ buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
93
+ };
94
+ // Set up the fragment stage
95
+ const fragment = {
96
+ module: cast(this.props.fs).handle,
97
+ entryPoint: this.props.fragmentEntryPoint || 'main',
98
+ targets: [
99
+ {
100
+ // TODO exclamation mark hack!
101
+ format: getWebGPUTextureFormat(this.device?.canvasContext?.format)
102
+ }
103
+ ]
104
+ };
105
+ // WebGPU has more restrictive topology support than WebGL
106
+ switch (this.props.topology) {
107
+ case 'triangle-fan-webgl':
108
+ case 'line-loop-webgl':
109
+ throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
110
+ default:
111
+ }
112
+ // Create a partially populated descriptor
113
+ const descriptor = {
114
+ vertex,
115
+ fragment,
116
+ primitive: {
117
+ topology: this.props.topology
118
+ },
119
+ layout: 'auto'
120
+ };
121
+ // Set parameters on the descriptor
122
+ applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
123
+ return descriptor;
133
124
  }
125
+ }
126
+ /**
127
+ _setAttributeBuffers(webgpuRenderPass: WebGPURenderPass) {
128
+ if (this._indexBuffer) {
129
+ webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);
130
+ }
134
131
 
135
- this._setAttributeBuffers(webgpuRenderPass);
136
-
137
- if (options.indexCount) {
138
- webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
139
- } else {
140
- webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount, options.firstIndex, options.firstInstance);
132
+ const buffers = this._getBuffers();
133
+ for (let i = 0; i < buffers.length; ++i) {
134
+ const buffer = cast<WebGPUBuffer>(buffers[i]);
135
+ if (!buffer) {
136
+ const attribute = this.props.shaderLayout.attributes.find(
137
+ (attribute) => attribute.location === i
138
+ );
139
+ throw new Error(
140
+ `No buffer provided for attribute '${attribute?.name || ''}' in Model '${this.props.id}'`
141
+ );
141
142
  }
143
+ webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);
142
144
  }
143
145
 
144
- _setAttributeBuffers(webgpuRenderPass) {
145
- if (this._indexBuffer) {
146
- webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);
146
+ // TODO - HANDLE buffer maps
147
+ /*
148
+ for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferLayout)) {
149
+ const buffer = cast<WebGPUBuffer>(this.props.attributes[bufferName]);
150
+ if (!buffer) {
151
+ log.warn(`Missing buffer for buffer map ${bufferName}`)();
152
+ continue;
147
153
  }
148
154
 
149
- const buffers = this._getBuffers();
150
-
151
- for (let i = 0; i < buffers.length; ++i) {
152
- const buffer = cast(buffers[i]);
153
-
154
- if (!buffer) {
155
- const attribute = this.props.layout.attributes.find(attribute => attribute.location === i);
156
- throw new Error("No buffer provided for attribute '".concat((attribute === null || attribute === void 0 ? void 0 : attribute.name) || '', "' in Model '").concat(this.props.id, "'"));
155
+ if ('location' in attributeMapping) {
156
+ // @ts-expect-error TODO model must not depend on webgpu
157
+ renderPass.handle.setVertexBuffer(layout.location, buffer.handle);
158
+ } else {
159
+ for (const [bufferName, mapping] of Object.entries(attributeMapping)) {
160
+ // @ts-expect-error TODO model must not depend on webgpu
161
+ renderPass.handle.setVertexBuffer(field.location, buffer.handle);
157
162
  }
158
-
159
- webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);
160
163
  }
161
164
  }
162
-
165
+ *
163
166
  }
164
- //# sourceMappingURL=webgpu-render-pipeline.js.map
167
+ */
@@ -1,13 +1,13 @@
1
- /// <reference types="@webgpu/types" />
2
- import { Sampler, SamplerProps } from '@luma.gl/api';
3
- import type WebGPUDevice from '../webgpu-device';
4
- export declare type WebGPUSamplerProps = SamplerProps & {
1
+ /// <reference types="dist" />
2
+ import { Sampler, SamplerProps } from '@luma.gl/core';
3
+ import type { WebGPUDevice } from "../webgpu-device.js";
4
+ export type WebGPUSamplerProps = SamplerProps & {
5
5
  handle?: GPUSampler;
6
6
  };
7
7
  /**
8
8
  *
9
9
  */
10
- export default class WebGPUSampler extends Sampler {
10
+ export declare class WebGPUSampler extends Sampler {
11
11
  readonly device: WebGPUDevice;
12
12
  readonly handle: GPUSampler;
13
13
  constructor(device: WebGPUDevice, props: WebGPUSamplerProps);
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD,oBAAY,kBAAkB,GAAG,YAAY,GAAG;IAC9C,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;gBAEhB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB;IAc3D,OAAO,IAAI,IAAI;CAGhB"}
1
+ {"version":3,"file":"webgpu-sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAC,YAAY,EAAC,4BAAyB;AAEnD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAC9C,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;gBAEhB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB;IAclD,OAAO,IAAI,IAAI;CAMzB"}
@@ -1,25 +1,25 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Sampler } from '@luma.gl/api';
3
- export default class WebGPUSampler extends Sampler {
4
- constructor(device, props) {
5
- super(device, props);
6
-
7
- _defineProperty(this, "device", void 0);
8
-
9
- _defineProperty(this, "handle", void 0);
10
-
11
- this.device = device;
12
- const samplerProps = this.props;
13
-
14
- if (samplerProps.type !== 'comparison-sampler') {
15
- delete samplerProps.compare;
1
+ import { Sampler } from '@luma.gl/core';
2
+ /**
3
+ *
4
+ */
5
+ export class WebGPUSampler extends Sampler {
6
+ device;
7
+ handle;
8
+ constructor(device, props) {
9
+ super(device, props);
10
+ this.device = device;
11
+ // Prepare sampler props
12
+ const samplerProps = { ...this.props };
13
+ if (samplerProps.type !== 'comparison-sampler') {
14
+ delete samplerProps.compare;
15
+ }
16
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
17
+ this.handle.label = this.props.id;
18
+ }
19
+ destroy() {
20
+ // GPUSampler does not have a destroy method
21
+ // this.handle.destroy();
22
+ // @ts-expect-error readonly
23
+ this.handle = null;
16
24
  }
17
-
18
- this.handle = this.handle || this.device.handle.createSampler(this.props);
19
- this.handle.label = this.props.id;
20
- }
21
-
22
- destroy() {}
23
-
24
25
  }
25
- //# sourceMappingURL=webgpu-sampler.js.map
@@ -1,21 +1,18 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { ShaderProps, CompilerMessage } from '@luma.gl/api';
3
- import { Shader } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
5
- export declare type WebGPUShaderProps = ShaderProps & {
6
- handle?: GPUShaderModule;
7
- };
1
+ /// <reference types="dist" />
2
+ import type { ShaderProps, CompilerMessage } from '@luma.gl/core';
3
+ import { Shader } from '@luma.gl/core';
4
+ import type { WebGPUDevice } from "../webgpu-device.js";
8
5
  /**
9
6
  * Immutable shader
10
7
  */
11
- export default class WebGPUShader extends Shader {
8
+ export declare class WebGPUShader extends Shader {
12
9
  readonly device: WebGPUDevice;
13
10
  readonly handle: GPUShaderModule;
14
- constructor(device: WebGPUDevice, props: WebGPUShaderProps);
15
- _checkCompilationError(errorScope: Promise<GPUError>): Promise<void>;
11
+ constructor(device: WebGPUDevice, props: ShaderProps);
12
+ _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void>;
16
13
  destroy(): void;
17
- protected createHandle(): GPUShaderModule;
18
14
  /** Returns compilation info for this shader */
19
- compilationInfo(): Promise<readonly CompilerMessage[]>;
15
+ getCompilationInfo(): Promise<readonly CompilerMessage[]>;
16
+ protected createHandle(): GPUShaderModule;
20
17
  }
21
18
  //# sourceMappingURL=webgpu-shader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAM,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,MAAM;IAC9C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB;IAYpD,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,OAAO;IAIP,SAAS,CAAC,YAAY,IAAI,eAAe;IAwBzC,+CAA+C;IACzC,eAAe,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;CAI7D"}
1
+ {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,MAAM,EAAM,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAC,4BAAyB;AAEnD;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW;IAY9C,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxE,OAAO,IAAI,IAAI;IAOxB,+CAA+C;IACzC,kBAAkB,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAO/D,SAAS,CAAC,YAAY,IAAI,eAAe;CAU1C"}
@@ -1,64 +1,51 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Shader, log } from '@luma.gl/api';
3
- export default class WebGPUShader extends Shader {
4
- constructor(device, props) {
5
- super(device, props);
6
-
7
- _defineProperty(this, "device", void 0);
8
-
9
- _defineProperty(this, "handle", void 0);
10
-
11
- this.device = device;
12
- this.device.handle.pushErrorScope('validation');
13
- this.handle = this.props.handle || this.createHandle();
14
- this.handle.label = this.props.id;
15
-
16
- this._checkCompilationError(this.device.handle.popErrorScope());
17
- }
18
-
19
- async _checkCompilationError(errorScope) {
20
- const error = await errorScope;
21
-
22
- if (error) {
23
- const shaderLog = await this.compilationInfo();
24
- log.error("Shader compilation error: ".concat(error.message), shaderLog)();
25
- throw new Error("Shader compilation error: ".concat(error.message));
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Shader, log } from '@luma.gl/core';
5
+ /**
6
+ * Immutable shader
7
+ */
8
+ export class WebGPUShader extends Shader {
9
+ device;
10
+ handle;
11
+ constructor(device, props) {
12
+ super(device, props);
13
+ this.device = device;
14
+ this.device.handle.pushErrorScope('validation');
15
+ this.handle = this.props.handle || this.createHandle();
16
+ this.handle.label = this.props.id;
17
+ this._checkCompilationError(this.device.handle.popErrorScope());
26
18
  }
27
- }
28
-
29
- destroy() {}
30
-
31
- createHandle() {
32
- const {
33
- source
34
- } = this.props;
35
- let language = this.props.language;
36
-
37
- if (!language) {
38
- language = source.includes('->') ? 'wgsl' : 'glsl';
19
+ async _checkCompilationError(errorScope) {
20
+ const error = (await errorScope);
21
+ if (error) {
22
+ // The `Shader` base class will determine if debug window should be opened based on props
23
+ this.debugShader();
24
+ const shaderLog = await this.getCompilationInfo();
25
+ log.error(`Shader compilation error: ${error.message}`, shaderLog)();
26
+ // Note: Even though this error is asynchronous and thrown after the constructor completes,
27
+ // it will result in a useful stack trace leading back to the constructor
28
+ throw new Error(`Shader compilation error: ${error.message}`);
29
+ }
39
30
  }
40
-
41
- switch (language) {
42
- case 'wgsl':
43
- return this.device.handle.createShaderModule({
44
- code: source
45
- });
46
-
47
- case 'glsl':
48
- return this.device.handle.createShaderModule({
49
- code: source,
50
- transform: glsl => this.device.glslang.compileGLSL(glsl, type)
51
- });
52
-
53
- default:
54
- throw new Error(language);
31
+ destroy() {
32
+ // Note: WebGPU does not offer a method to destroy shaders
33
+ // this.handle.destroy();
34
+ // @ts-expect-error readonly
35
+ this.handle = null;
36
+ }
37
+ /** Returns compilation info for this shader */
38
+ async getCompilationInfo() {
39
+ const compilationInfo = await this.handle.getCompilationInfo();
40
+ return compilationInfo.messages;
41
+ }
42
+ // PRIVATE METHODS
43
+ createHandle() {
44
+ const { source } = this.props;
45
+ const isGLSL = source.includes('#version');
46
+ if (this.props.language === 'glsl' || isGLSL) {
47
+ throw new Error('GLSL shaders are not supported in WebGPU');
48
+ }
49
+ return this.device.handle.createShaderModule({ code: source });
55
50
  }
56
- }
57
-
58
- async compilationInfo() {
59
- const compilationInfo = await this.handle.compilationInfo();
60
- return compilationInfo.messages;
61
- }
62
-
63
51
  }
64
- //# sourceMappingURL=webgpu-shader.js.map
@@ -0,0 +1,20 @@
1
+ /// <reference types="dist" />
2
+ import { TextureView, TextureViewProps } from '@luma.gl/core';
3
+ import type { WebGPUDevice } from "../webgpu-device.js";
4
+ import type { WebGPUTexture } from "./webgpu-texture.js";
5
+ export type WebGPUTextureViewProps = TextureViewProps & {
6
+ handle?: GPUTextureView;
7
+ };
8
+ /**
9
+ *
10
+ */
11
+ export declare class WebGPUTextureView extends TextureView {
12
+ readonly device: WebGPUDevice;
13
+ readonly handle: GPUTextureView;
14
+ readonly texture: WebGPUTexture;
15
+ constructor(device: WebGPUDevice, props: WebGPUTextureViewProps & {
16
+ texture: WebGPUTexture;
17
+ });
18
+ destroy(): void;
19
+ }
20
+ //# sourceMappingURL=webgpu-texture-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu-texture-view.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-texture-view.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAC,YAAY,EAAC,4BAAyB;AACnD,OAAO,KAAK,EAAC,aAAa,EAAC,4BAAyB;AAEpD,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,GAAG;IACtD,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;gBAEpB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,GAAG;QAAC,OAAO,EAAE,aAAa,CAAA;KAAC;IAmBjF,OAAO,IAAI,IAAI;CAMzB"}
@@ -0,0 +1,35 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { TextureView } from '@luma.gl/core';
5
+ /**
6
+ *
7
+ */
8
+ export class WebGPUTextureView extends TextureView {
9
+ device;
10
+ handle;
11
+ texture;
12
+ constructor(device, props) {
13
+ super(device, props);
14
+ this.device = device;
15
+ this.texture = props.texture;
16
+ this.handle =
17
+ this.handle ||
18
+ this.texture.handle.createView({
19
+ format: (props.format || this.texture.format),
20
+ dimension: props.dimension || this.texture.dimension,
21
+ aspect: props.aspect,
22
+ baseMipLevel: props.baseMipLevel,
23
+ mipLevelCount: props.mipLevelCount, // GPUIntegerCoordinate;
24
+ baseArrayLayer: props.baseArrayLayer, // GPUIntegerCoordinate;
25
+ arrayLayerCount: props.arrayLayerCount // GPUIntegerCoordinate;
26
+ });
27
+ this.handle.label = this.props.id;
28
+ }
29
+ destroy() {
30
+ // GPUTextureView does not have a destroy method
31
+ // this.handle.destroy();
32
+ // @ts-expect-error readonly
33
+ this.handle = null;
34
+ }
35
+ }