@luma.gl/webgpu 9.0.0-beta.3 → 9.0.0-beta.5
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/dist/adapter/helpers/accessor-to-format.js +99 -1
- package/dist/adapter/helpers/convert-texture-format.js +5 -5
- package/dist/adapter/helpers/generate-mipmaps.js +76 -82
- package/dist/adapter/helpers/get-bind-group.js +54 -41
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +110 -80
- package/dist/adapter/helpers/webgpu-parameters.js +182 -125
- package/dist/adapter/resources/webgpu-buffer.js +110 -62
- package/dist/adapter/resources/webgpu-command-encoder.js +73 -49
- package/dist/adapter/resources/webgpu-compute-pass.js +54 -41
- package/dist/adapter/resources/webgpu-compute-pipeline.js +24 -19
- package/dist/adapter/resources/webgpu-external-texture.js +29 -19
- package/dist/adapter/resources/webgpu-framebuffer.js +11 -7
- package/dist/adapter/resources/webgpu-query.js +42 -1
- package/dist/adapter/resources/webgpu-render-pass.js +115 -105
- package/dist/adapter/resources/webgpu-render-pipeline.js +148 -83
- package/dist/adapter/resources/webgpu-sampler.js +18 -15
- package/dist/adapter/resources/webgpu-shader.js +55 -45
- package/dist/adapter/resources/webgpu-texture.js +129 -109
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +4 -1
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +64 -41
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +100 -69
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +257 -230
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/dist.dev.js +661 -2178
- package/dist/glsl/glsllang.js +9 -6
- package/dist/index.cjs +58 -239
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +9 -6
- package/dist.min.js +1 -22
- package/package.json +9 -7
- package/src/adapter/resources/webgpu-vertex-array.ts +5 -2
- package/src/adapter/webgpu-canvas-context.ts +1 -0
- package/src/adapter/webgpu-device.ts +16 -36
- 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.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.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/resources/webgpu-vertex-array.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.js.map +0 -1
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,137 +1,194 @@
|
|
|
1
1
|
function addDepthStencil(descriptor) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
descriptor.depthStencil = descriptor.depthStencil || {
|
|
3
|
+
// required, set something
|
|
4
|
+
format: 'depth24plus',
|
|
5
|
+
stencilFront: {},
|
|
6
|
+
stencilBack: {},
|
|
7
|
+
// TODO can this cause trouble? Should we set to WebGPU defaults? Are there defaults?
|
|
8
|
+
depthWriteEnabled: false,
|
|
9
|
+
depthCompare: 'less-equal'
|
|
10
|
+
};
|
|
11
|
+
return descriptor.depthStencil;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Supports for luma.gl's flat parameter space
|
|
15
|
+
* Populates the corresponding sub-objects in a GPURenderPipelineDescriptor
|
|
16
|
+
*/
|
|
17
|
+
// @ts-expect-error
|
|
11
18
|
export const PARAMETER_TABLE = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
19
|
+
// RASTERIZATION PARAMETERS
|
|
20
|
+
cullMode: (parameter, value, descriptor) => {
|
|
21
|
+
descriptor.primitive = descriptor.primitive || {};
|
|
22
|
+
descriptor.primitive.cullMode = value;
|
|
23
|
+
},
|
|
24
|
+
frontFace: (parameter, value, descriptor) => {
|
|
25
|
+
descriptor.primitive = descriptor.primitive || {};
|
|
26
|
+
descriptor.primitive.frontFace = value;
|
|
27
|
+
},
|
|
28
|
+
// DEPTH
|
|
29
|
+
depthWriteEnabled: (parameter, value, descriptor) => {
|
|
30
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
31
|
+
depthStencil.depthWriteEnabled = value;
|
|
32
|
+
},
|
|
33
|
+
depthCompare: (parameter, value, descriptor) => {
|
|
34
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
35
|
+
depthStencil.depthCompare = value;
|
|
36
|
+
},
|
|
37
|
+
depthFormat: (parameter, value, descriptor) => {
|
|
38
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
39
|
+
depthStencil.format = value;
|
|
40
|
+
},
|
|
41
|
+
depthBias: (parameter, value, descriptor) => {
|
|
42
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
43
|
+
depthStencil.depthBias = value;
|
|
44
|
+
},
|
|
45
|
+
depthBiasSlopeScale: (parameter, value, descriptor) => {
|
|
46
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
47
|
+
depthStencil.depthBiasSlopeScale = value;
|
|
48
|
+
},
|
|
49
|
+
depthBiasClamp: (parameter, value, descriptor) => {
|
|
50
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
51
|
+
depthStencil.depthBiasClamp = value;
|
|
52
|
+
},
|
|
53
|
+
// STENCIL
|
|
54
|
+
stencilReadMask: (parameter, value, descriptor) => {
|
|
55
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
56
|
+
depthStencil.stencilReadMask = value;
|
|
57
|
+
},
|
|
58
|
+
stencilWriteMask: (parameter, value, descriptor) => {
|
|
59
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
60
|
+
depthStencil.stencilWriteMask = value;
|
|
61
|
+
},
|
|
62
|
+
stencilCompare: (parameter, value, descriptor) => {
|
|
63
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
64
|
+
depthStencil.stencilFront.compare = value;
|
|
65
|
+
depthStencil.stencilBack.compare = value;
|
|
66
|
+
},
|
|
67
|
+
stencilPassOperation: (parameter, value, descriptor) => {
|
|
68
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
69
|
+
depthStencil.stencilFront.passOp = value;
|
|
70
|
+
depthStencil.stencilBack.passOp = value;
|
|
71
|
+
},
|
|
72
|
+
stencilFailOperation: (parameter, value, descriptor) => {
|
|
73
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
74
|
+
depthStencil.stencilFront.failOp = value;
|
|
75
|
+
depthStencil.stencilBack.failOp = value;
|
|
76
|
+
},
|
|
77
|
+
stencilDepthFailOperation: (parameter, value, descriptor) => {
|
|
78
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
79
|
+
depthStencil.stencilFront.depthFailOp = value;
|
|
80
|
+
depthStencil.stencilBack.depthFailOp = value;
|
|
81
|
+
},
|
|
82
|
+
// MULTISAMPLE
|
|
83
|
+
sampleCount: (parameter, value, descriptor) => {
|
|
84
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
85
|
+
descriptor.multisample.count = value;
|
|
86
|
+
},
|
|
87
|
+
sampleMask: (parameter, value, descriptor) => {
|
|
88
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
89
|
+
descriptor.multisample.mask = value;
|
|
90
|
+
},
|
|
91
|
+
sampleAlphaToCoverageEnabled: (parameter, value, descriptor) => {
|
|
92
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
93
|
+
descriptor.multisample.alphaToCoverageEnabled = value;
|
|
94
|
+
},
|
|
95
|
+
// COLOR
|
|
96
|
+
colorMask: (parameter, value, descriptor) => {
|
|
97
|
+
const targets = addColorState(descriptor);
|
|
98
|
+
targets[0].writeMask = value;
|
|
99
|
+
},
|
|
100
|
+
blendColorOperation: (parameter, value, descriptor) => {
|
|
101
|
+
addColorState(descriptor);
|
|
102
|
+
// const targets = addColorState(descriptor);
|
|
103
|
+
// const target = targets[0];
|
|
104
|
+
// const blend: GPUBlendState = target.blend || {color: {alpha: 0}};
|
|
105
|
+
// blend.color = blend.color || {};
|
|
106
|
+
// target.blend.color.operation = value;
|
|
107
|
+
}
|
|
108
|
+
/*
|
|
109
|
+
blendColorSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
110
|
+
addColorState(descriptor);
|
|
111
|
+
targets[0].blend = targets[0].blend || {};
|
|
112
|
+
targets[0].blend.color = targets[0].blend.color || {};
|
|
113
|
+
targets[0].blend.color.srcTarget = value;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
blendColorDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
117
|
+
addColorState(descriptor);
|
|
118
|
+
targets[0].blend = targets[0].blend || {};
|
|
119
|
+
targets[0].blend.color = targets[0].blend.color || {};
|
|
120
|
+
targets[0].blend.color.dstTarget = value;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
blendAlphaOperation: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
124
|
+
addColorState(descriptor);
|
|
125
|
+
targets[0].blend = targets[0].blend || {};
|
|
126
|
+
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
127
|
+
targets[0].blend.alpha.operation = value;
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
blendAlphaSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
131
|
+
addColorState(descriptor);
|
|
132
|
+
targets[0].blend = targets[0].blend || {};
|
|
133
|
+
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
134
|
+
targets[0].blend.alpha.srcTarget = value;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
blendAlphaDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
138
|
+
addColorState(descriptor);
|
|
139
|
+
targets[0].blend = targets[0].blend || {};
|
|
140
|
+
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
141
|
+
targets[0].blend.alpha.dstTarget = value;
|
|
142
|
+
},
|
|
143
|
+
*/
|
|
91
144
|
};
|
|
92
145
|
const DEFAULT_PIPELINE_DESCRIPTOR = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
146
|
+
// depthStencil: {
|
|
147
|
+
// stencilFront: {},
|
|
148
|
+
// stencilBack: {},
|
|
149
|
+
// // depthWriteEnabled: true,
|
|
150
|
+
// // depthCompare: 'less',
|
|
151
|
+
// // format: 'depth24plus-stencil8',
|
|
152
|
+
// },
|
|
153
|
+
primitive: {
|
|
154
|
+
cullMode: 'back',
|
|
155
|
+
topology: 'triangle-list'
|
|
156
|
+
},
|
|
157
|
+
vertex: {
|
|
158
|
+
module: undefined,
|
|
159
|
+
entryPoint: 'main'
|
|
160
|
+
},
|
|
161
|
+
fragment: {
|
|
162
|
+
module: undefined,
|
|
163
|
+
entryPoint: 'main',
|
|
164
|
+
targets: [
|
|
165
|
+
// { format: props.color0Format || 'bgra8unorm' }
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
layout: 'auto'
|
|
107
169
|
};
|
|
108
|
-
export function applyParametersToRenderPipelineDescriptor(pipelineDescriptor) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...pipelineDescriptor
|
|
113
|
-
});
|
|
114
|
-
setParameters(pipelineDescriptor, parameters);
|
|
170
|
+
export function applyParametersToRenderPipelineDescriptor(pipelineDescriptor, parameters = {}) {
|
|
171
|
+
// Apply defaults
|
|
172
|
+
Object.assign(pipelineDescriptor, { ...DEFAULT_PIPELINE_DESCRIPTOR, ...pipelineDescriptor });
|
|
173
|
+
setParameters(pipelineDescriptor, parameters);
|
|
115
174
|
}
|
|
175
|
+
// Apply any supplied parameters
|
|
116
176
|
function setParameters(pipelineDescriptor, parameters) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
177
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
178
|
+
const setterFunction = PARAMETER_TABLE[key];
|
|
179
|
+
if (!setterFunction) {
|
|
180
|
+
throw new Error(`Illegal parameter ${key}`);
|
|
181
|
+
}
|
|
182
|
+
setterFunction(key, value, pipelineDescriptor);
|
|
121
183
|
}
|
|
122
|
-
setterFunction(key, value, pipelineDescriptor);
|
|
123
|
-
}
|
|
124
184
|
}
|
|
125
185
|
function addColorState(descriptor) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
return (_descriptor$fragment4 = descriptor.fragment) === null || _descriptor$fragment4 === void 0 ? void 0 : _descriptor$fragment4.targets;
|
|
186
|
+
descriptor.fragment.targets = descriptor.fragment?.targets || [];
|
|
187
|
+
if (!Array.isArray(descriptor.fragment?.targets)) {
|
|
188
|
+
throw new Error('colorstate');
|
|
189
|
+
}
|
|
190
|
+
if (descriptor.fragment?.targets?.length === 0) {
|
|
191
|
+
descriptor.fragment.targets?.push({});
|
|
192
|
+
}
|
|
193
|
+
return descriptor.fragment?.targets;
|
|
136
194
|
}
|
|
137
|
-
//# sourceMappingURL=webgpu-parameters.js.map
|
|
@@ -1,70 +1,118 @@
|
|
|
1
|
+
// WEBGPU Buffer implementation
|
|
1
2
|
import { Buffer } from '@luma.gl/core';
|
|
2
3
|
function getByteLength(props) {
|
|
3
|
-
|
|
4
|
-
return props.byteLength || ((_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.byteLength) || 0;
|
|
4
|
+
return props.byteLength || props.data?.byteLength || 0;
|
|
5
5
|
}
|
|
6
6
|
export class WebGPUBuffer extends Buffer {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
device;
|
|
8
|
+
handle;
|
|
9
|
+
byteLength;
|
|
10
|
+
constructor(device, props) {
|
|
11
|
+
super(device, props);
|
|
12
|
+
this.device = device;
|
|
13
|
+
this.byteLength = getByteLength(props);
|
|
14
|
+
const mapBuffer = Boolean(props.data);
|
|
15
|
+
// WebGPU buffers must be aligned to 4 bytes
|
|
16
|
+
const size = Math.ceil(this.byteLength / 4) * 4;
|
|
17
|
+
this.handle = this.props.handle || this.device.handle.createBuffer({
|
|
18
|
+
size,
|
|
19
|
+
// usage defaults to vertex
|
|
20
|
+
usage: this.props.usage || (GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST),
|
|
21
|
+
mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
|
|
22
|
+
label: this.props.id
|
|
23
|
+
});
|
|
24
|
+
if (props.data) {
|
|
25
|
+
this._writeMapped(props.data);
|
|
26
|
+
// this.handle.writeAsync({data: props.data, map: false, unmap: false});
|
|
27
|
+
}
|
|
28
|
+
if (mapBuffer && !props.mappedAtCreation) {
|
|
29
|
+
this.handle.unmap();
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
destroy() {
|
|
33
|
+
this.handle.destroy();
|
|
27
34
|
}
|
|
35
|
+
// WebGPU provides multiple ways to write a buffer...
|
|
36
|
+
write(data, byteOffset = 0) {
|
|
37
|
+
this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
|
|
38
|
+
}
|
|
39
|
+
async readAsync(byteOffset = 0, byteLength = this.byteLength) {
|
|
40
|
+
// We need MAP_READ flag, but only COPY_DST buffers can have MAP_READ flag, so we need to create a temp buffer
|
|
41
|
+
const tempBuffer = new WebGPUBuffer(this.device, { usage: Buffer.MAP_READ | Buffer.COPY_DST, byteLength });
|
|
42
|
+
// Now do a GPU-side copy into the temp buffer we can actually read.
|
|
43
|
+
// TODO - we are spinning up an independent command queue here, what does this mean
|
|
44
|
+
const commandEncoder = this.device.handle.createCommandEncoder();
|
|
45
|
+
commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
|
|
46
|
+
this.device.handle.queue.submit([commandEncoder.finish()]);
|
|
47
|
+
// Map the temp buffer and read the data.
|
|
48
|
+
await tempBuffer.handle.mapAsync(GPUMapMode.READ, byteOffset, byteLength);
|
|
49
|
+
const arrayBuffer = tempBuffer.handle.getMappedRange().slice(0);
|
|
50
|
+
tempBuffer.handle.unmap();
|
|
51
|
+
tempBuffer.destroy();
|
|
52
|
+
return new Uint8Array(arrayBuffer);
|
|
53
|
+
}
|
|
54
|
+
_writeMapped(typedArray) {
|
|
55
|
+
const arrayBuffer = this.handle.getMappedRange();
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
new typedArray.constructor(arrayBuffer).set(typedArray);
|
|
58
|
+
}
|
|
59
|
+
// WEBGPU API
|
|
60
|
+
mapAsync(mode, offset = 0, size) {
|
|
61
|
+
return this.handle.mapAsync(mode, offset, size);
|
|
62
|
+
}
|
|
63
|
+
getMappedRange(offset = 0, size) {
|
|
64
|
+
return this.handle.getMappedRange(offset, size);
|
|
65
|
+
}
|
|
66
|
+
unmap() {
|
|
67
|
+
this.handle.unmap();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/*
|
|
71
|
+
// Convenience API
|
|
72
|
+
/** Read data from the buffer *
|
|
73
|
+
async readAsync(options: {
|
|
74
|
+
byteOffset?: number,
|
|
75
|
+
byteLength?: number,
|
|
76
|
+
map?: boolean,
|
|
77
|
+
unmap?: boolean
|
|
78
|
+
}): Promise<ArrayBuffer> {
|
|
79
|
+
if (options.map ?? true) {
|
|
80
|
+
await this.mapAsync(Buffer.MAP_READ, options.byteOffset, options.byteLength);
|
|
81
|
+
}
|
|
82
|
+
const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
|
|
83
|
+
if (options.unmap ?? true) {
|
|
84
|
+
this.unmap();
|
|
85
|
+
}
|
|
86
|
+
return arrayBuffer;
|
|
28
87
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
tempBuffer.handle.unmap();
|
|
49
|
-
tempBuffer.destroy();
|
|
50
|
-
return new Uint8Array(arrayBuffer);
|
|
51
|
-
}
|
|
52
|
-
_writeMapped(typedArray) {
|
|
53
|
-
const arrayBuffer = this.handle.getMappedRange();
|
|
54
|
-
new typedArray.constructor(arrayBuffer).set(typedArray);
|
|
55
|
-
}
|
|
56
|
-
mapAsync(mode) {
|
|
57
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
58
|
-
let size = arguments.length > 2 ? arguments[2] : undefined;
|
|
59
|
-
return this.handle.mapAsync(mode, offset, size);
|
|
60
|
-
}
|
|
61
|
-
getMappedRange() {
|
|
62
|
-
let offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
63
|
-
let size = arguments.length > 1 ? arguments[1] : undefined;
|
|
64
|
-
return this.handle.getMappedRange(offset, size);
|
|
65
|
-
}
|
|
66
|
-
unmap() {
|
|
67
|
-
this.handle.unmap();
|
|
88
|
+
|
|
89
|
+
/** Write data to the buffer *
|
|
90
|
+
async writeAsync(options: {
|
|
91
|
+
data: ArrayBuffer,
|
|
92
|
+
byteOffset?: number,
|
|
93
|
+
byteLength?: number,
|
|
94
|
+
map?: boolean,
|
|
95
|
+
unmap?: boolean
|
|
96
|
+
}): Promise<void> {
|
|
97
|
+
if (options.map ?? true) {
|
|
98
|
+
await this.mapAsync(Buffer.MAP_WRITE, options.byteOffset, options.byteLength);
|
|
99
|
+
}
|
|
100
|
+
const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
|
|
101
|
+
const destArray = new Uint8Array(arrayBuffer);
|
|
102
|
+
const srcArray = new Uint8Array(options.data);
|
|
103
|
+
destArray.set(srcArray);
|
|
104
|
+
if (options.unmap ?? true) {
|
|
105
|
+
this.unmap();
|
|
106
|
+
}
|
|
68
107
|
}
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
*/
|
|
109
|
+
// Mapped API (WebGPU)
|
|
110
|
+
/** Maps the memory so that it can be read *
|
|
111
|
+
// abstract mapAsync(mode, byteOffset, byteLength): Promise<void>
|
|
112
|
+
|
|
113
|
+
/** Get the mapped range of data for reading or writing *
|
|
114
|
+
// abstract getMappedRange(byteOffset, byteLength): ArrayBuffer;
|
|
115
|
+
|
|
116
|
+
/** unmap makes the contents of the buffer available to the GPU again *
|
|
117
|
+
// abstract unmap(): void;
|
|
118
|
+
*/
|
|
@@ -1,52 +1,76 @@
|
|
|
1
1
|
import { CommandEncoder } from '@luma.gl/core';
|
|
2
2
|
export class WebGPUCommandEncoder extends CommandEncoder {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
3
|
+
device;
|
|
4
|
+
handle;
|
|
5
|
+
constructor(device, props) {
|
|
6
|
+
super(device, props);
|
|
7
|
+
this.device = device;
|
|
8
|
+
this.handle =
|
|
9
|
+
props.handle ||
|
|
10
|
+
this.device.handle.createCommandEncoder({
|
|
11
|
+
// TODO was this removed in standard?
|
|
12
|
+
// measureExecutionTime: this.props.measureExecutionTime
|
|
13
|
+
});
|
|
14
|
+
this.handle.label = this.props.id;
|
|
15
|
+
}
|
|
16
|
+
destroy() { }
|
|
17
|
+
finish(options) {
|
|
18
|
+
return this.finish(options);
|
|
19
|
+
}
|
|
20
|
+
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
21
|
+
// beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
|
|
22
|
+
copyBufferToBuffer(options) {
|
|
23
|
+
const webgpuSourceBuffer = options.source;
|
|
24
|
+
const WebGPUDestinationBuffer = options.destination;
|
|
25
|
+
this.handle.copyBufferToBuffer(webgpuSourceBuffer.handle, options.sourceOffset ?? 0, WebGPUDestinationBuffer.handle, options.destinationOffset ?? 0, options.size ?? 0);
|
|
26
|
+
}
|
|
27
|
+
copyBufferToTexture(options) {
|
|
28
|
+
const webgpuSourceBuffer = options.source;
|
|
29
|
+
const WebGPUDestinationTexture = options.destination;
|
|
30
|
+
this.handle.copyBufferToTexture({
|
|
31
|
+
buffer: webgpuSourceBuffer.handle,
|
|
32
|
+
offset: options.offset ?? 0,
|
|
33
|
+
bytesPerRow: options.bytesPerRow,
|
|
34
|
+
rowsPerImage: options.rowsPerImage
|
|
35
|
+
}, {
|
|
36
|
+
texture: WebGPUDestinationTexture.handle,
|
|
37
|
+
mipLevel: options.mipLevel ?? 0,
|
|
38
|
+
origin: options.origin ?? {}
|
|
39
|
+
// aspect: options.aspect
|
|
40
|
+
}, {
|
|
41
|
+
// TODO exclamation mark hack
|
|
42
|
+
width: options.extent[0],
|
|
43
|
+
height: options.extent[1],
|
|
44
|
+
depthOrArrayLayers: options.extent[2]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
copyTextureToBuffer(options) {
|
|
48
|
+
// this.handle.copyTextureToBuffer(
|
|
49
|
+
// // source
|
|
50
|
+
// {},
|
|
51
|
+
// // destination
|
|
52
|
+
// {},
|
|
53
|
+
// // copySize
|
|
54
|
+
// {}
|
|
55
|
+
// );
|
|
56
|
+
}
|
|
57
|
+
copyTextureToTexture(options) {
|
|
58
|
+
// this.handle.copyTextureToTexture(
|
|
59
|
+
// // source
|
|
60
|
+
// {},
|
|
61
|
+
// // destination
|
|
62
|
+
// {},
|
|
63
|
+
// // copySize
|
|
64
|
+
// {}
|
|
65
|
+
// );
|
|
66
|
+
}
|
|
67
|
+
pushDebugGroup(groupLabel) {
|
|
68
|
+
this.handle.pushDebugGroup(groupLabel);
|
|
69
|
+
}
|
|
70
|
+
popDebugGroup() {
|
|
71
|
+
this.handle.popDebugGroup();
|
|
72
|
+
}
|
|
73
|
+
insertDebugMarker(markerLabel) {
|
|
74
|
+
this.handle.insertDebugMarker(markerLabel);
|
|
75
|
+
}
|
|
51
76
|
}
|
|
52
|
-
//# sourceMappingURL=webgpu-command-encoder.js.map
|