@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.
- package/LICENSE +3 -1
- package/dist/adapter/helpers/accessor-to-format.js +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -6
- package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +61 -52
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +123 -90
- package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +184 -130
- package/dist/adapter/resources/webgpu-buffer.d.ts +14 -5
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +117 -70
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +13 -14
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +83 -65
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +19 -13
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +78 -57
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +16 -6
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +48 -26
- package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +38 -29
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +15 -109
- package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
- package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-query-set.js +27 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts +14 -7
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +136 -91
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +63 -23
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +151 -148
- package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +23 -23
- package/dist/adapter/resources/webgpu-shader.d.ts +9 -12
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +47 -60
- package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
- package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-texture-view.js +35 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +20 -10
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +133 -105
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +27 -0
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-vertex-array.js +66 -0
- package/dist/adapter/webgpu-canvas-context.d.ts +17 -12
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +105 -92
- package/dist/adapter/webgpu-device.d.ts +45 -30
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +266 -241
- package/dist/dist.dev.js +1664 -0
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +1432 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -8
- package/dist.min.js +9 -0
- package/package.json +22 -11
- package/src/adapter/helpers/accessor-to-format.ts +6 -3
- package/src/adapter/helpers/convert-texture-format.ts +5 -2
- package/src/adapter/helpers/get-bind-group.ts +30 -14
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +73 -39
- package/src/adapter/helpers/webgpu-parameters.ts +99 -29
- package/src/adapter/resources/webgpu-buffer.ts +85 -17
- package/src/adapter/resources/webgpu-command-encoder.ts +93 -58
- package/src/adapter/resources/webgpu-compute-pass.ts +56 -32
- package/src/adapter/resources/webgpu-compute-pipeline.ts +51 -18
- package/src/adapter/resources/webgpu-external-texture.ts +19 -11
- package/src/adapter/resources/webgpu-framebuffer.ts +11 -108
- package/src/adapter/resources/webgpu-query-set.ts +37 -0
- package/src/adapter/resources/webgpu-render-pass.ts +95 -19
- package/src/adapter/resources/webgpu-render-pipeline.ts +139 -159
- package/src/adapter/resources/webgpu-sampler.ts +10 -7
- package/src/adapter/resources/webgpu-shader.ts +30 -35
- package/src/adapter/resources/webgpu-texture-view.ts +46 -0
- package/src/adapter/resources/webgpu-texture.ts +75 -41
- package/src/adapter/resources/webgpu-vertex-array.ts +91 -0
- package/src/adapter/webgpu-canvas-context.ts +60 -29
- package/src/adapter/webgpu-device.ts +219 -120
- package/src/index.ts +8 -9
- package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.d.ts +0 -10
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.js +0 -95
- package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-query.d.ts +0 -1
- package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
- package/dist/adapter/resources/webgpu-query.js +0 -2
- package/dist/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/adapter/webgpu-device.js.map +0 -1
- package/dist/adapter/webgpu-types.d.ts +0 -1
- package/dist/adapter/webgpu-types.d.ts.map +0 -1
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/adapter/webgpu-types.js.map +0 -1
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/glsl/glsllang.d.ts +0 -3
- package/dist/glsl/glsllang.d.ts.map +0 -1
- package/dist/glsl/glsllang.js +0 -10
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.d.ts +0 -2
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -4
- package/dist/init.js.map +0 -1
- package/src/adapter/helpers/generate-mipmaps.ts +0 -107
- package/src/adapter/resources/webgpu-query.ts +0 -43
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/bundle.ts +0 -4
- package/src/glsl/glsllang.ts +0 -14
- package/src/init.ts +0 -4
|
@@ -1,164 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
import { RenderPipeline, cast, log
|
|
3
|
-
import { applyParametersToRenderPipelineDescriptor } from
|
|
4
|
-
import { getWebGPUTextureFormat } from
|
|
5
|
-
import { getBindGroup } from
|
|
6
|
-
import { getVertexBufferLayout
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
167
|
+
*/
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/// <reference types="
|
|
2
|
-
import { Sampler, SamplerProps } from '@luma.gl/
|
|
3
|
-
import type WebGPUDevice from
|
|
4
|
-
export
|
|
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
|
|
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,
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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="
|
|
2
|
-
import type { ShaderProps, CompilerMessage } from '@luma.gl/
|
|
3
|
-
import { Shader } from '@luma.gl/
|
|
4
|
-
import type WebGPUDevice from
|
|
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
|
|
8
|
+
export declare class WebGPUShader extends Shader {
|
|
12
9
|
readonly device: WebGPUDevice;
|
|
13
10
|
readonly handle: GPUShaderModule;
|
|
14
|
-
constructor(device: WebGPUDevice, props:
|
|
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
|
-
|
|
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":";
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
}
|