@luma.gl/webgpu 9.0.0-beta.1 → 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/dist/adapter/helpers/accessor-to-format.js +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -5
- package/dist/adapter/helpers/get-bind-group.d.ts +3 -3
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +57 -41
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +185 -125
- package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +119 -62
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +15 -9
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +76 -41
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +14 -4
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +46 -19
- package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +35 -18
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
- 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 +4 -2
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +133 -105
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +52 -5
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +151 -78
- package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +21 -15
- package/dist/adapter/resources/webgpu-shader.d.ts +2 -5
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +45 -44
- 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 +8 -8
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +130 -107
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +9 -8
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
- package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +101 -67
- package/dist/adapter/webgpu-device.d.ts +26 -28
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +254 -220
- package/dist/dist.dev.js +804 -2270
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +366 -485
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist.min.js +1 -22
- package/package.json +9 -7
- package/src/adapter/helpers/accessor-to-format.ts +5 -1
- package/src/adapter/helpers/convert-texture-format.ts +4 -1
- package/src/adapter/helpers/get-bind-group.ts +12 -6
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +13 -5
- package/src/adapter/helpers/webgpu-parameters.ts +79 -15
- package/src/adapter/resources/webgpu-buffer.ts +24 -11
- package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
- package/src/adapter/resources/webgpu-compute-pass.ts +45 -22
- package/src/adapter/resources/webgpu-compute-pipeline.ts +48 -16
- package/src/adapter/resources/webgpu-external-texture.ts +14 -6
- package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
- package/src/adapter/resources/webgpu-query-set.ts +37 -0
- package/src/adapter/resources/webgpu-render-pass.ts +37 -14
- package/src/adapter/resources/webgpu-render-pipeline.ts +80 -119
- package/src/adapter/resources/webgpu-sampler.ts +4 -1
- package/src/adapter/resources/webgpu-shader.ts +14 -25
- package/src/adapter/resources/webgpu-texture-view.ts +46 -0
- package/src/adapter/resources/webgpu-texture.ts +33 -28
- package/src/adapter/resources/webgpu-vertex-array.ts +28 -20
- package/src/adapter/webgpu-canvas-context.ts +10 -4
- package/src/adapter/webgpu-device.ts +109 -106
- package/src/index.ts +2 -1
- 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 -100
- 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/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.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/glsl/glsllang.d.ts +0 -3
- package/dist/glsl/glsllang.d.ts.map +0 -1
- package/dist/glsl/glsllang.js +0 -9
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.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/glsl/glsllang.ts +0 -14
|
@@ -1,2 +1,103 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/*
|
|
5
|
+
import {assert} from '@luma.gl/core';
|
|
1
6
|
|
|
2
|
-
|
|
7
|
+
type Accessor = Record<string, any>;
|
|
8
|
+
|
|
9
|
+
const FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {
|
|
10
|
+
uchar2: {type: 'uchar', size: 2},
|
|
11
|
+
uchar4: {type: 'uchar', size: 4},
|
|
12
|
+
char2: {type: 'char', size: 2},
|
|
13
|
+
char4: {type: 'char', size: 4},
|
|
14
|
+
uchar2norm: {type: 'uchar', size: 2, normalized: true},
|
|
15
|
+
uchar4norm: {type: 'uchar', size: 4, normalized: true},
|
|
16
|
+
char2norm: {type: 'char', size: 2, normalized: true},
|
|
17
|
+
char4norm: {type: 'char', size: 4, normalized: true},
|
|
18
|
+
ushort2: {type: 'ushort', size: 2},
|
|
19
|
+
ushort4: {type: 'ushort', size: 4},
|
|
20
|
+
short2: {type: 'short', size: 2},
|
|
21
|
+
short4: {type: 'short', size: 4},
|
|
22
|
+
ushort2norm: {type: 'ushort', size: 2, normalized: true},
|
|
23
|
+
ushort4norm: {type: 'ushort', size: 4, normalized: true},
|
|
24
|
+
short2norm: {type: 'short', size: 1, normalized: true},
|
|
25
|
+
short4norm: {type: 'short', size: 1, normalized: true},
|
|
26
|
+
half2: {type: 'half', size: 2},
|
|
27
|
+
half4: {type: 'half', size: 4},
|
|
28
|
+
float: {type: 'float', size: 1},
|
|
29
|
+
float2: {type: 'float', size: 2},
|
|
30
|
+
float3: {type: 'float', size: 3},
|
|
31
|
+
float4: {type: 'float', size: 4},
|
|
32
|
+
uint: {type: 'uint', size: 1, integer: true},
|
|
33
|
+
uint2: {type: 'uint', size: 2, integer: true},
|
|
34
|
+
uint3: {type: 'uint', size: 3, integer: true},
|
|
35
|
+
uint4: {type: 'uint', size: 4, integer: true},
|
|
36
|
+
int: {type: 'int', size: 1, integer: true},
|
|
37
|
+
int2: {type: 'int', size: 2, integer: true},
|
|
38
|
+
int3: {type: 'int', size: 3, integer: true},
|
|
39
|
+
int4: {type: 'int', size: 4, integer: true}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}
|
|
44
|
+
* @param {*} format
|
|
45
|
+
*
|
|
46
|
+
export function mapWebGPUFormatToAccessor(format) {
|
|
47
|
+
const accessorDefinition = FORMAT_TO_ACCESSOR[format];
|
|
48
|
+
assert(accessorDefinition, 'invalid attribute format');
|
|
49
|
+
return Object.freeze(accessorDefinition);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings
|
|
54
|
+
* @param {*} format
|
|
55
|
+
*
|
|
56
|
+
export function mapAccessorToWebGPUFormat(accessor) {
|
|
57
|
+
const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;
|
|
58
|
+
assert(size >=1 && size <=4);
|
|
59
|
+
// `norm` suffix (uchar4norm)
|
|
60
|
+
const norm = normalized ? 'norm' : '';
|
|
61
|
+
// size 1 is ommitted in format names (float vs float2)
|
|
62
|
+
const count = size === 1 ? '' : size;
|
|
63
|
+
switch (type) {
|
|
64
|
+
case GL.UNSIGNED_BYTE:
|
|
65
|
+
switch (size) {
|
|
66
|
+
case 2:
|
|
67
|
+
case 4:
|
|
68
|
+
return `uchar${count}${norm}`;
|
|
69
|
+
}
|
|
70
|
+
case GL.BYTE:
|
|
71
|
+
switch (size) {
|
|
72
|
+
case 2:
|
|
73
|
+
case 4:
|
|
74
|
+
return `char${count}${norm}`;
|
|
75
|
+
}
|
|
76
|
+
case GL.UNSIGNED_SHORT:
|
|
77
|
+
switch (size) {
|
|
78
|
+
case 2:
|
|
79
|
+
case 4:
|
|
80
|
+
return `ushort${count}${norm}`;
|
|
81
|
+
}
|
|
82
|
+
case GL.SHORT:
|
|
83
|
+
switch (size) {
|
|
84
|
+
case 2:
|
|
85
|
+
case 4:
|
|
86
|
+
return `short${count}${norm}`;
|
|
87
|
+
}
|
|
88
|
+
case GL.HALF_FLOAT:
|
|
89
|
+
switch (size) {
|
|
90
|
+
case 2:
|
|
91
|
+
case 4:
|
|
92
|
+
return `half${count}`;
|
|
93
|
+
}
|
|
94
|
+
case GL.FLOAT:
|
|
95
|
+
return `float${count}`;
|
|
96
|
+
case GL.UNSIGNED_INT:
|
|
97
|
+
return `uint${count}`;
|
|
98
|
+
case GL.INT:
|
|
99
|
+
return `int${count}`;
|
|
100
|
+
}
|
|
101
|
+
throw new Error('illegal accessor');
|
|
102
|
+
}
|
|
103
|
+
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-texture-format.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/convert-texture-format.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"convert-texture-format.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/convert-texture-format.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAE5C,mDAAmD;AACnD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAK9E"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Ensure a texture format is WebGPU compatible */
|
|
1
5
|
export function getWebGPUTextureFormat(format) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
if (format.includes('webgl')) {
|
|
7
|
+
throw new Error('webgl-only format');
|
|
8
|
+
}
|
|
9
|
+
return format;
|
|
6
10
|
}
|
|
7
|
-
//# sourceMappingURL=convert-texture-format.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="dist" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComputeShaderLayout, BindingDeclaration, Binding } from '@luma.gl/core';
|
|
3
3
|
/**
|
|
4
4
|
* Create a WebGPU "bind group layout" from an array of luma.gl bindings
|
|
5
5
|
* @note bind groups can be automatically generated by WebGPU.
|
|
@@ -8,6 +8,6 @@ export declare function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGr
|
|
|
8
8
|
/**
|
|
9
9
|
* Create a WebGPU "bind group" from an array of luma.gl bindings
|
|
10
10
|
*/
|
|
11
|
-
export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, shaderLayout:
|
|
12
|
-
export declare function getShaderLayoutBinding(shaderLayout:
|
|
11
|
+
export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, shaderLayout: ComputeShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
|
|
12
|
+
export declare function getShaderLayoutBinding(shaderLayout: ComputeShaderLayout, bindingName: string): BindingDeclaration;
|
|
13
13
|
//# sourceMappingURL=get-bind-group.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAC,mBAAmB,EAAE,kBAAkB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAMpF;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,OAAO,EAAE,GAClB,kBAAkB,CAMpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,eAAe,EAAE,kBAAkB,EACnC,YAAY,EAAE,mBAAmB,EACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,mBAAmB,EACjC,WAAW,EAAE,MAAM,GAClB,kBAAkB,CASpB"}
|
|
@@ -1,53 +1,69 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/core';
|
|
5
|
+
/**
|
|
6
|
+
* Create a WebGPU "bind group layout" from an array of luma.gl bindings
|
|
7
|
+
* @note bind groups can be automatically generated by WebGPU.
|
|
8
|
+
*/
|
|
2
9
|
export function makeBindGroupLayout(device, layout, bindings) {
|
|
3
|
-
|
|
10
|
+
throw new Error('not implemented');
|
|
11
|
+
// return device.createBindGroupLayout({
|
|
12
|
+
// layout,
|
|
13
|
+
// entries: getBindGroupEntries(bindings)
|
|
14
|
+
// })
|
|
4
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a WebGPU "bind group" from an array of luma.gl bindings
|
|
18
|
+
*/
|
|
5
19
|
export function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
const entries = getBindGroupEntries(bindings, shaderLayout);
|
|
21
|
+
return device.createBindGroup({
|
|
22
|
+
layout: bindGroupLayout,
|
|
23
|
+
entries
|
|
24
|
+
});
|
|
11
25
|
}
|
|
12
26
|
export function getShaderLayoutBinding(shaderLayout, bindingName) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
const bindingLayout = shaderLayout.bindings.find(binding => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
|
|
28
|
+
if (!bindingLayout) {
|
|
29
|
+
log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
|
|
30
|
+
}
|
|
31
|
+
return bindingLayout;
|
|
18
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* @param bindings
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
19
37
|
function getBindGroupEntries(bindings, shaderLayout) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
const entries = [];
|
|
39
|
+
for (const [bindingName, value] of Object.entries(bindings)) {
|
|
40
|
+
const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
|
|
41
|
+
if (bindingLayout) {
|
|
42
|
+
entries.push(getBindGroupEntry(value, bindingLayout.location));
|
|
43
|
+
}
|
|
25
44
|
}
|
|
26
|
-
|
|
27
|
-
return entries;
|
|
45
|
+
return entries;
|
|
28
46
|
}
|
|
29
47
|
function getBindGroupEntry(binding, index) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
throw new Error('invalid binding');
|
|
48
|
+
if (binding instanceof Buffer) {
|
|
49
|
+
return {
|
|
50
|
+
binding: index,
|
|
51
|
+
resource: {
|
|
52
|
+
buffer: cast(binding).handle
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (binding instanceof Sampler) {
|
|
57
|
+
return {
|
|
58
|
+
binding: index,
|
|
59
|
+
resource: cast(binding).handle
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else if (binding instanceof Texture) {
|
|
63
|
+
return {
|
|
64
|
+
binding: index,
|
|
65
|
+
resource: cast(binding).handle.createView({ label: 'bind-group-auto-created' })
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
throw new Error('invalid binding');
|
|
52
69
|
}
|
|
53
|
-
//# sourceMappingURL=get-bind-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-vertex-buffer-layout.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-vertex-buffer-layout.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"get-vertex-buffer-layout.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-vertex-buffer-layout.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAqC,MAAM,eAAe,CAAC;AAYlG;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAAE,GAC3B,qBAAqB,EAAE,CA4EzB;AAED,wBAAgB,cAAc,CAC5B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BxB"}
|
|
@@ -1,94 +1,131 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { log, decodeVertexFormat } from '@luma.gl/core';
|
|
5
|
+
// import {getAttributeInfosFromLayouts} from '@luma.gl/core';
|
|
6
|
+
/** Throw error on any WebGL-only vertex formats */
|
|
2
7
|
function getWebGPUVertexFormat(format) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
if (format.endsWith('-webgl')) {
|
|
9
|
+
throw new Error(`WebGPU does not support vertex format ${format}`);
|
|
10
|
+
}
|
|
11
|
+
return format;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.
|
|
15
|
+
* Converts luma.gl attribute definitions to a WebGPU GPUVertexBufferLayout[] array
|
|
16
|
+
* @param layout
|
|
17
|
+
* @param bufferLayout The buffer map is optional
|
|
18
|
+
* @returns WebGPU layout intended for a GPURenderPassDescriptor.
|
|
19
|
+
*/
|
|
8
20
|
export function getVertexBufferLayout(shaderLayout, bufferLayout) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const vertexBufferLayouts = [];
|
|
22
|
+
const usedAttributes = new Set();
|
|
23
|
+
// First handle any buffers mentioned in `bufferLayout`
|
|
24
|
+
for (const mapping of bufferLayout) {
|
|
25
|
+
// Build vertex attributes for one buffer
|
|
26
|
+
const vertexAttributes = [];
|
|
27
|
+
// TODO verify that all stepModes for one buffer are the same
|
|
28
|
+
let stepMode = 'vertex';
|
|
29
|
+
let byteStride = 0;
|
|
30
|
+
// interleaved mapping {..., attributes: [{...}, ...]}
|
|
31
|
+
if (mapping.attributes) {
|
|
32
|
+
// const arrayStride = mapping.byteStride; TODO
|
|
33
|
+
for (const attributeMapping of mapping.attributes) {
|
|
34
|
+
const attributeName = attributeMapping.attribute;
|
|
35
|
+
const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
|
|
36
|
+
stepMode =
|
|
37
|
+
attributeLayout.stepMode ||
|
|
38
|
+
(attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
|
|
39
|
+
vertexAttributes.push({
|
|
40
|
+
format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
|
|
41
|
+
offset: attributeMapping.byteOffset,
|
|
42
|
+
shaderLocation: attributeLayout.location
|
|
43
|
+
});
|
|
44
|
+
byteStride += decodeVertexFormat(mapping.format).byteLength;
|
|
45
|
+
}
|
|
46
|
+
// non-interleaved mapping (just set offset and stride)
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
|
|
50
|
+
if (!attributeLayout) {
|
|
51
|
+
continue; // eslint-disable-line no-continue
|
|
52
|
+
}
|
|
53
|
+
byteStride = decodeVertexFormat(mapping.format).byteLength;
|
|
54
|
+
stepMode =
|
|
55
|
+
attributeLayout.stepMode ||
|
|
56
|
+
(attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
|
|
57
|
+
vertexAttributes.push({
|
|
58
|
+
format: getWebGPUVertexFormat(mapping.format),
|
|
59
|
+
// We only support 0 offset for non-interleaved buffer layouts
|
|
60
|
+
offset: 0,
|
|
61
|
+
shaderLocation: attributeLayout.location
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Store all the attribute bindings for one buffer
|
|
65
|
+
vertexBufferLayouts.push({
|
|
66
|
+
arrayStride: mapping.byteStride || byteStride,
|
|
67
|
+
stepMode,
|
|
68
|
+
attributes: vertexAttributes
|
|
24
69
|
});
|
|
25
|
-
byteStride += decodeVertexFormat(mapping.format).byteLength;
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
|
|
29
|
-
if (!attributeLayout) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
byteStride = decodeVertexFormat(mapping.format).byteLength;
|
|
33
|
-
stepMode = attributeLayout.stepMode || 'vertex';
|
|
34
|
-
vertexAttributes.push({
|
|
35
|
-
format: getWebGPUVertexFormat(mapping.format),
|
|
36
|
-
offset: 0,
|
|
37
|
-
shaderLocation: attributeLayout.location
|
|
38
|
-
});
|
|
39
70
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}]
|
|
56
|
-
});
|
|
71
|
+
// Add any non-mapped attributes - TODO - avoid hardcoded types
|
|
72
|
+
for (const attribute of shaderLayout.attributes) {
|
|
73
|
+
if (!usedAttributes.has(attribute.name)) {
|
|
74
|
+
vertexBufferLayouts.push({
|
|
75
|
+
arrayStride: decodeVertexFormat('float32x3').byteLength,
|
|
76
|
+
stepMode: attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'),
|
|
77
|
+
attributes: [
|
|
78
|
+
{
|
|
79
|
+
format: getWebGPUVertexFormat('float32x3'),
|
|
80
|
+
offset: 0,
|
|
81
|
+
shaderLocation: attribute.location
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
57
86
|
}
|
|
58
|
-
|
|
59
|
-
return vertexBufferLayouts;
|
|
87
|
+
return vertexBufferLayouts;
|
|
60
88
|
}
|
|
61
89
|
export function getBufferSlots(shaderLayout, bufferLayout) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
const usedAttributes = new Set();
|
|
91
|
+
let bufferSlot = 0;
|
|
92
|
+
const bufferSlots = {};
|
|
93
|
+
// First handle any buffers mentioned in `bufferLayout`
|
|
94
|
+
for (const mapping of bufferLayout) {
|
|
95
|
+
// interleaved mapping {..., attributes: [{...}, ...]}
|
|
96
|
+
if ('attributes' in mapping) {
|
|
97
|
+
for (const interleaved of mapping.attributes) {
|
|
98
|
+
usedAttributes.add(interleaved.attribute);
|
|
99
|
+
}
|
|
100
|
+
// non-interleaved mapping (just set offset and stride)
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
usedAttributes.add(mapping.name);
|
|
104
|
+
}
|
|
105
|
+
bufferSlots[mapping.name] = bufferSlot++;
|
|
72
106
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
// Add any non-mapped attributes
|
|
108
|
+
for (const attribute of shaderLayout.attributes) {
|
|
109
|
+
if (!usedAttributes.has(attribute.name)) {
|
|
110
|
+
bufferSlots[attribute.name] = bufferSlot++;
|
|
111
|
+
}
|
|
78
112
|
}
|
|
79
|
-
|
|
80
|
-
return bufferSlots;
|
|
113
|
+
return bufferSlots;
|
|
81
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Looks up an attribute in the ShaderLayout.
|
|
117
|
+
* @throws if name is not in ShaderLayout
|
|
118
|
+
* @throws if name has already been referenced
|
|
119
|
+
*/
|
|
82
120
|
function findAttributeLayout(shaderLayout, name, attributeNames) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
121
|
+
const attribute = shaderLayout.attributes.find(attribute => attribute.name === name);
|
|
122
|
+
if (!attribute) {
|
|
123
|
+
log.warn(`Unknown attribute ${name}`)();
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (attributeNames.has(name)) {
|
|
127
|
+
throw new Error(`Duplicate attribute ${name}`);
|
|
128
|
+
}
|
|
129
|
+
attributeNames.add(name);
|
|
130
|
+
return attribute;
|
|
93
131
|
}
|
|
94
|
-
//# sourceMappingURL=get-vertex-buffer-layout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpu-parameters.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgpu-parameters.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"webgpu-parameters.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgpu-parameters.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAezC;;;GAGG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAkN9D,CAAC;AAgCF,wBAAgB,yCAAyC,CACvD,kBAAkB,EAAE,2BAA2B,EAC/C,UAAU,GAAE,UAAe,GAC1B,IAAI,CAIN"}
|