@luma.gl/webgpu 9.0.0-alpha.16 → 9.0.0-alpha.19
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 +1 -100
- package/dist/adapter/helpers/accessor-to-format.js.map +1 -0
- package/dist/adapter/helpers/convert-texture-format.d.ts +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +5 -5
- package/dist/adapter/helpers/convert-texture-format.js.map +1 -0
- package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +85 -88
- package/dist/adapter/helpers/generate-mipmaps.js.map +1 -0
- package/dist/adapter/helpers/get-bind-group.d.ts +1 -1
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +39 -54
- package/dist/adapter/helpers/get-bind-group.js.map +1 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +72 -97
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
- package/dist/adapter/helpers/webgpu-parameters.d.ts +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +125 -182
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -0
- package/dist/adapter/resources/webgpu-buffer.d.ts +2 -2
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +63 -57
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -0
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +2 -2
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +46 -47
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +2 -2
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +41 -51
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +2 -2
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +20 -22
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
- 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 +20 -26
- package/dist/adapter/resources/webgpu-external-texture.js.map +1 -0
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +2 -2
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +86 -89
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -0
- package/dist/adapter/resources/webgpu-query.js +1 -42
- package/dist/adapter/resources/webgpu-query.js.map +1 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts +2 -2
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +70 -64
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -0
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +2 -2
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +118 -158
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgpu-sampler.d.ts +3 -3
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +16 -16
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -0
- package/dist/adapter/resources/webgpu-shader.d.ts +3 -3
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +44 -47
- package/dist/adapter/resources/webgpu-shader.js.map +1 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +3 -2
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +87 -100
- package/dist/adapter/resources/webgpu-texture.js.map +1 -0
- package/dist/adapter/webgpu-canvas-context.d.ts +2 -2
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +68 -77
- package/dist/adapter/webgpu-canvas-context.js.map +1 -0
- package/dist/adapter/webgpu-device.d.ts +2 -2
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +194 -215
- package/dist/adapter/webgpu-device.js.map +1 -0
- package/dist/adapter/webgpu-types.js +2 -0
- package/dist/adapter/webgpu-types.js.map +1 -0
- package/dist/dist.dev.js +3061 -0
- package/dist/glsl/glsllang.js +6 -9
- package/dist/glsl/glsllang.js.map +1 -0
- package/dist/index.cjs +1442 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -0
- package/dist.min.js +17 -0
- package/package.json +17 -8
- package/src/adapter/helpers/generate-mipmaps.ts +1 -1
- package/src/adapter/helpers/get-bind-group.ts +1 -1
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +2 -2
- package/src/adapter/helpers/webgpu-parameters.ts +9 -9
- package/src/adapter/resources/webgpu-buffer.ts +1 -1
- package/src/adapter/resources/webgpu-command-encoder.ts +4 -4
- package/src/adapter/resources/webgpu-compute-pass.ts +1 -1
- package/src/adapter/resources/webgpu-compute-pipeline.ts +1 -1
- package/src/adapter/resources/webgpu-external-texture.ts +1 -1
- package/src/adapter/resources/webgpu-framebuffer.ts +6 -6
- package/src/adapter/resources/webgpu-query.ts +1 -1
- package/src/adapter/resources/webgpu-render-pass.ts +1 -1
- package/src/adapter/resources/webgpu-render-pipeline.ts +3 -3
- package/src/adapter/resources/webgpu-sampler.ts +1 -1
- package/src/adapter/resources/webgpu-shader.ts +3 -1
- package/src/adapter/resources/webgpu-texture.ts +1 -1
- package/src/adapter/webgpu-canvas-context.ts +1 -1
- package/src/adapter/webgpu-device.ts +3 -2
- package/src/index.ts +2 -5
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -4
- package/dist/dist.js +0 -8051
- package/dist/dist.min.js +0 -1
- package/dist/es5/adapter/helpers/accessor-to-format.js +0 -2
- package/dist/es5/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/es5/adapter/helpers/convert-texture-format.js +0 -13
- package/dist/es5/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/es5/adapter/helpers/generate-mipmaps.js +0 -103
- package/dist/es5/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/es5/adapter/helpers/get-bind-group.js +0 -66
- package/dist/es5/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js +0 -149
- package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/es5/adapter/helpers/webgpu-parameters.js +0 -150
- package/dist/es5/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-buffer.js +0 -131
- package/dist/es5/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-command-encoder.js +0 -90
- package/dist/es5/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-compute-pass.js +0 -85
- package/dist/es5/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-compute-pipeline.js +0 -48
- package/dist/es5/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-external-texture.js +0 -50
- package/dist/es5/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-framebuffer.js +0 -126
- package/dist/es5/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-query.js +0 -2
- package/dist/es5/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-render-pass.js +0 -124
- package/dist/es5/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-render-pipeline.js +0 -185
- package/dist/es5/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-sampler.js +0 -45
- package/dist/es5/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-shader.js +0 -125
- package/dist/es5/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/es5/adapter/resources/webgpu-texture.js +0 -138
- package/dist/es5/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/es5/adapter/webgpu-canvas-context.js +0 -111
- package/dist/es5/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/es5/adapter/webgpu-device.js +0 -317
- package/dist/es5/adapter/webgpu-device.js.map +0 -1
- package/dist/es5/adapter/webgpu-types.js +0 -2
- package/dist/es5/adapter/webgpu-types.js.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/glsl/glsllang.js +0 -47
- package/dist/es5/glsl/glsllang.js.map +0 -1
- package/dist/es5/index.js +0 -44
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/init.js +0 -7
- package/dist/es5/init.js.map +0 -1
- package/dist/esm/adapter/helpers/accessor-to-format.js +0 -2
- package/dist/esm/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/esm/adapter/helpers/convert-texture-format.js +0 -7
- package/dist/esm/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/esm/adapter/helpers/generate-mipmaps.js +0 -88
- package/dist/esm/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/esm/adapter/helpers/get-bind-group.js +0 -51
- package/dist/esm/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js +0 -83
- package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/esm/adapter/helpers/webgpu-parameters.js +0 -137
- package/dist/esm/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-buffer.js +0 -70
- package/dist/esm/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-command-encoder.js +0 -49
- package/dist/esm/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-compute-pass.js +0 -44
- package/dist/esm/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-compute-pipeline.js +0 -23
- package/dist/esm/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-external-texture.js +0 -23
- package/dist/esm/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-framebuffer.js +0 -93
- package/dist/esm/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-query.js +0 -2
- package/dist/esm/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-render-pass.js +0 -79
- package/dist/esm/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-render-pipeline.js +0 -130
- package/dist/esm/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-sampler.js +0 -20
- package/dist/esm/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-shader.js +0 -50
- package/dist/esm/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/esm/adapter/resources/webgpu-texture.js +0 -95
- package/dist/esm/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/esm/adapter/webgpu-canvas-context.js +0 -74
- package/dist/esm/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/esm/adapter/webgpu-device.js +0 -196
- package/dist/esm/adapter/webgpu-device.js.map +0 -1
- package/dist/esm/adapter/webgpu-types.js +0 -2
- package/dist/esm/adapter/webgpu-types.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/glsl/glsllang.js +0 -9
- package/dist/esm/glsl/glsllang.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/init.js +0 -4
- package/dist/esm/init.js.map +0 -1
- package/dist/init.d.ts +0 -2
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -3
- package/src/bundle.ts +0 -4
- package/src/init.ts +0 -4
|
@@ -1,101 +1,2 @@
|
|
|
1
|
-
/*
|
|
2
|
-
import {assert} from '@luma.gl/api';
|
|
3
|
-
import GL from '@luma.gl/constants';
|
|
4
1
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {
|
|
8
|
-
uchar2: {type: 'uchar', size: 2},
|
|
9
|
-
uchar4: {type: 'uchar', size: 4},
|
|
10
|
-
char2: {type: 'char', size: 2},
|
|
11
|
-
char4: {type: 'char', size: 4},
|
|
12
|
-
uchar2norm: {type: 'uchar', size: 2, normalized: true},
|
|
13
|
-
uchar4norm: {type: 'uchar', size: 4, normalized: true},
|
|
14
|
-
char2norm: {type: 'char', size: 2, normalized: true},
|
|
15
|
-
char4norm: {type: 'char', size: 4, normalized: true},
|
|
16
|
-
ushort2: {type: 'ushort', size: 2},
|
|
17
|
-
ushort4: {type: 'ushort', size: 4},
|
|
18
|
-
short2: {type: 'short', size: 2},
|
|
19
|
-
short4: {type: 'short', size: 4},
|
|
20
|
-
ushort2norm: {type: 'ushort', size: 2, normalized: true},
|
|
21
|
-
ushort4norm: {type: 'ushort', size: 4, normalized: true},
|
|
22
|
-
short2norm: {type: 'short', size: 1, normalized: true},
|
|
23
|
-
short4norm: {type: 'short', size: 1, normalized: true},
|
|
24
|
-
half2: {type: 'half', size: 2},
|
|
25
|
-
half4: {type: 'half', size: 4},
|
|
26
|
-
float: {type: 'float', size: 1},
|
|
27
|
-
float2: {type: 'float', size: 2},
|
|
28
|
-
float3: {type: 'float', size: 3},
|
|
29
|
-
float4: {type: 'float', size: 4},
|
|
30
|
-
uint: {type: 'uint', size: 1, integer: true},
|
|
31
|
-
uint2: {type: 'uint', size: 2, integer: true},
|
|
32
|
-
uint3: {type: 'uint', size: 3, integer: true},
|
|
33
|
-
uint4: {type: 'uint', size: 4, integer: true},
|
|
34
|
-
int: {type: 'int', size: 1, integer: true},
|
|
35
|
-
int2: {type: 'int', size: 2, integer: true},
|
|
36
|
-
int3: {type: 'int', size: 3, integer: true},
|
|
37
|
-
int4: {type: 'int', size: 4, integer: true}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}
|
|
42
|
-
* @param {*} format
|
|
43
|
-
*
|
|
44
|
-
export function mapWebGPUFormatToAccessor(format) {
|
|
45
|
-
const accessorDefinition = FORMAT_TO_ACCESSOR[format];
|
|
46
|
-
assert(accessorDefinition, 'invalid attribute format');
|
|
47
|
-
return Object.freeze(accessorDefinition);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings
|
|
52
|
-
* @param {*} format
|
|
53
|
-
*
|
|
54
|
-
export function mapAccessorToWebGPUFormat(accessor) {
|
|
55
|
-
const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;
|
|
56
|
-
assert(size >=1 && size <=4);
|
|
57
|
-
// `norm` suffix (uchar4norm)
|
|
58
|
-
const norm = normalized ? 'norm' : '';
|
|
59
|
-
// size 1 is ommitted in format names (float vs float2)
|
|
60
|
-
const count = size === 1 ? '' : size;
|
|
61
|
-
switch (type) {
|
|
62
|
-
case GL.UNSIGNED_BYTE:
|
|
63
|
-
switch (size) {
|
|
64
|
-
case 2:
|
|
65
|
-
case 4:
|
|
66
|
-
return `uchar${count}${norm}`;
|
|
67
|
-
}
|
|
68
|
-
case GL.BYTE:
|
|
69
|
-
switch (size) {
|
|
70
|
-
case 2:
|
|
71
|
-
case 4:
|
|
72
|
-
return `char${count}${norm}`;
|
|
73
|
-
}
|
|
74
|
-
case GL.UNSIGNED_SHORT:
|
|
75
|
-
switch (size) {
|
|
76
|
-
case 2:
|
|
77
|
-
case 4:
|
|
78
|
-
return `ushort${count}${norm}`;
|
|
79
|
-
}
|
|
80
|
-
case GL.SHORT:
|
|
81
|
-
switch (size) {
|
|
82
|
-
case 2:
|
|
83
|
-
case 4:
|
|
84
|
-
return `short${count}${norm}`;
|
|
85
|
-
}
|
|
86
|
-
case GL.HALF_FLOAT:
|
|
87
|
-
switch (size) {
|
|
88
|
-
case 2:
|
|
89
|
-
case 4:
|
|
90
|
-
return `half${count}`;
|
|
91
|
-
}
|
|
92
|
-
case GL.FLOAT:
|
|
93
|
-
return `float${count}`;
|
|
94
|
-
case GL.UNSIGNED_INT:
|
|
95
|
-
return `uint${count}`;
|
|
96
|
-
case GL.INT:
|
|
97
|
-
return `int${count}`;
|
|
98
|
-
}
|
|
99
|
-
throw new Error('illegal accessor');
|
|
100
|
-
}
|
|
101
|
-
*/
|
|
2
|
+
//# sourceMappingURL=accessor-to-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessor-to-format.js","names":[],"sources":["../../../src/adapter/helpers/accessor-to-format.ts"],"sourcesContent":["/*\nimport {assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\ntype Accessor = Record<string, any>;\n\nconst FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {\n uchar2: {type: 'uchar', size: 2},\n uchar4: {type: 'uchar', size: 4},\n char2: {type: 'char', size: 2},\n char4: {type: 'char', size: 4},\n uchar2norm: {type: 'uchar', size: 2, normalized: true},\n uchar4norm: {type: 'uchar', size: 4, normalized: true},\n char2norm: {type: 'char', size: 2, normalized: true},\n char4norm: {type: 'char', size: 4, normalized: true},\n ushort2: {type: 'ushort', size: 2},\n ushort4: {type: 'ushort', size: 4},\n short2: {type: 'short', size: 2},\n short4: {type: 'short', size: 4},\n ushort2norm: {type: 'ushort', size: 2, normalized: true},\n ushort4norm: {type: 'ushort', size: 4, normalized: true},\n short2norm: {type: 'short', size: 1, normalized: true},\n short4norm: {type: 'short', size: 1, normalized: true},\n half2: {type: 'half', size: 2},\n half4: {type: 'half', size: 4},\n float: {type: 'float', size: 1},\n float2: {type: 'float', size: 2},\n float3: {type: 'float', size: 3},\n float4: {type: 'float', size: 4},\n uint: {type: 'uint', size: 1, integer: true},\n uint2: {type: 'uint', size: 2, integer: true},\n uint3: {type: 'uint', size: 3, integer: true},\n uint4: {type: 'uint', size: 4, integer: true},\n int: {type: 'int', size: 1, integer: true},\n int2: {type: 'int', size: 2, integer: true},\n int3: {type: 'int', size: 3, integer: true},\n int4: {type: 'int', size: 4, integer: true}\n};\n\n/**\n * Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}\n * @param {*} format\n *\nexport function mapWebGPUFormatToAccessor(format) {\n const accessorDefinition = FORMAT_TO_ACCESSOR[format];\n assert(accessorDefinition, 'invalid attribute format');\n return Object.freeze(accessorDefinition);\n}\n\n/**\n * Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings\n * @param {*} format\n *\nexport function mapAccessorToWebGPUFormat(accessor) {\n const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;\n assert(size >=1 && size <=4);\n // `norm` suffix (uchar4norm)\n const norm = normalized ? 'norm' : '';\n // size 1 is ommitted in format names (float vs float2)\n const count = size === 1 ? '' : size;\n switch (type) {\n case GL.UNSIGNED_BYTE:\n switch (size) {\n case 2:\n case 4:\n return `uchar${count}${norm}`;\n }\n case GL.BYTE:\n switch (size) {\n case 2:\n case 4:\n return `char${count}${norm}`;\n }\n case GL.UNSIGNED_SHORT:\n switch (size) {\n case 2:\n case 4:\n return `ushort${count}${norm}`;\n }\n case GL.SHORT:\n switch (size) {\n case 2:\n case 4:\n return `short${count}${norm}`;\n }\n case GL.HALF_FLOAT:\n switch (size) {\n case 2:\n case 4:\n return `half${count}`;\n }\n case GL.FLOAT:\n return `float${count}`;\n case GL.UNSIGNED_INT:\n return `uint${count}`;\n case GL.INT:\n return `int${count}`;\n }\n throw new Error('illegal accessor');\n}\n*/"],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** Ensure a texture format is WebGPU compatible */
|
|
2
1
|
export function getWebGPUTextureFormat(format) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
if (format.includes('webgl')) {
|
|
3
|
+
throw new Error('webgl-only format');
|
|
4
|
+
}
|
|
5
|
+
return format;
|
|
7
6
|
}
|
|
7
|
+
//# sourceMappingURL=convert-texture-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-texture-format.js","names":["getWebGPUTextureFormat","format","includes","Error"],"sources":["../../../src/adapter/helpers/convert-texture-format.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {TextureFormat} from '@luma.gl/api';\n\n/** Ensure a texture format is WebGPU compatible */\nexport function getWebGPUTextureFormat(format: TextureFormat): GPUTextureFormat {\n if (format.includes('webgl')) {\n throw new Error('webgl-only format');\n }\n return format as GPUTextureFormat;\n}\n"],"mappings":"AAIA,OAAO,SAASA,sBAAsBA,CAACC,MAAqB,EAAoB;EAC9E,IAAIA,MAAM,CAACC,QAAQ,CAAC,OAAO,CAAC,EAAE;IAC5B,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EACA,OAAOF,MAAM;AACf"}
|
|
@@ -1,91 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// @ts-nocheck this is written against outdated WebGPU API, needs an update pass
|
|
5
|
-
const VS_GEN_MIPMAP = `\#version 450
|
|
6
|
-
const vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));
|
|
7
|
-
layout(location = 0) out vec2 vTex;
|
|
8
|
-
void main() {
|
|
9
|
-
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
|
10
|
-
vTex = gl_Position / 2.0f + vec2(0.5f);
|
|
11
|
-
}`;
|
|
12
|
-
const FS_GEN_MIPMAP = `#version 450
|
|
13
|
-
layout(set = 0, binding = 0) uniform sampler imgSampler;
|
|
14
|
-
layout(set = 0, binding = 1) uniform texture2D img;
|
|
15
|
-
layout(location = 0) in vec2 vTex;
|
|
16
|
-
layout(location = 0) out vec4 outColor;
|
|
17
|
-
void main() {
|
|
18
|
-
outColor = texture(sampler2D(img, imgSampler), vTex);
|
|
19
|
-
}`;
|
|
20
|
-
/** WebGPU does not have built-in mipmap creation */
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
const VS_GEN_MIPMAP = "#version 450\nconst vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));\nlayout(location = 0) out vec2 vTex;\nvoid main() {\n gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n vTex = gl_Position / 2.0f + vec2(0.5f);\n}";
|
|
3
|
+
const FS_GEN_MIPMAP = "#version 450\nlayout(set = 0, binding = 0) uniform sampler imgSampler;\nlayout(set = 0, binding = 1) uniform texture2D img;\nlayout(location = 0) in vec2 vTex;\nlayout(location = 0) out vec4 outColor;\nvoid main() {\n outColor = texture(sampler2D(img, imgSampler), vTex);\n}";
|
|
21
4
|
export class WebGPUMipmapGenerator {
|
|
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
|
-
|
|
5
|
+
constructor(device, glslang) {
|
|
6
|
+
_defineProperty(this, "device", void 0);
|
|
7
|
+
_defineProperty(this, "mipmapSampler", void 0);
|
|
8
|
+
_defineProperty(this, "mipmapPipeline", void 0);
|
|
9
|
+
this.device = device;
|
|
10
|
+
this.mipmapSampler = device.createSampler({
|
|
11
|
+
minFilter: 'linear'
|
|
12
|
+
});
|
|
13
|
+
this.mipmapPipeline = device.createRenderPipeline({
|
|
14
|
+
vertexStage: {
|
|
15
|
+
module: device.createShaderModule({
|
|
16
|
+
code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')
|
|
17
|
+
}),
|
|
18
|
+
entryPoint: 'main'
|
|
19
|
+
},
|
|
20
|
+
fragmentStage: {
|
|
21
|
+
module: device.createShaderModule({
|
|
22
|
+
code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')
|
|
23
|
+
}),
|
|
24
|
+
entryPoint: 'main'
|
|
25
|
+
},
|
|
26
|
+
primitiveTopology: 'triangle-strip',
|
|
27
|
+
colorStates: [{
|
|
28
|
+
format: 'rgba8unorm'
|
|
29
|
+
}]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
generateMipmappedTexture(imageBitmap) {
|
|
33
|
+
const textureSize = {
|
|
34
|
+
width: imageBitmap.width,
|
|
35
|
+
height: imageBitmap.height,
|
|
36
|
+
depth: 1
|
|
37
|
+
};
|
|
38
|
+
const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
|
|
39
|
+
const texture = this.device.createTexture({
|
|
40
|
+
size: textureSize,
|
|
41
|
+
format: 'rgba8unorm',
|
|
42
|
+
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
|
|
43
|
+
mipLevelCount
|
|
44
|
+
});
|
|
45
|
+
this.device.queue.copyImageBitmapToTexture({
|
|
46
|
+
imageBitmap
|
|
47
|
+
}, {
|
|
48
|
+
texture: srcTexture
|
|
49
|
+
}, textureSize);
|
|
50
|
+
const commandEncoder = this.device.createCommandEncoder({});
|
|
51
|
+
for (let i = 1; i < mipLevelCount; ++i) {
|
|
52
|
+
const passEncoder = commandEncoder.beginRenderPass({
|
|
53
|
+
colorAttachments: [{
|
|
54
|
+
attachment: texture.createView({
|
|
55
|
+
baseMipLevel: i,
|
|
56
|
+
mipLevelCount: 1
|
|
57
|
+
}),
|
|
58
|
+
loadValue: {
|
|
59
|
+
r: 1.0,
|
|
60
|
+
g: 0.0,
|
|
61
|
+
b: 0.0,
|
|
62
|
+
a: 0.0
|
|
63
|
+
}
|
|
64
|
+
}]
|
|
65
|
+
});
|
|
66
|
+
const bindGroup = this.device.createBindGroup({
|
|
67
|
+
layout: this.mipmapPipeline.getBindGroupLayout(0),
|
|
68
|
+
bindings: [{
|
|
69
|
+
binding: 0,
|
|
70
|
+
resource: this.mipmapSampler
|
|
71
|
+
}, {
|
|
72
|
+
binding: 1,
|
|
73
|
+
resource: texture.createView({
|
|
74
|
+
baseMipLevel: i - 1,
|
|
75
|
+
mipLevelCount: 1
|
|
76
|
+
})
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
79
|
+
passEncoder.setPipeline(this.mipmapPipeline);
|
|
80
|
+
passEncoder.setBindGroup(0, bindGroup);
|
|
81
|
+
passEncoder.draw(4);
|
|
82
|
+
passEncoder.endPass();
|
|
90
83
|
}
|
|
84
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
85
|
+
return texture;
|
|
86
|
+
}
|
|
91
87
|
}
|
|
88
|
+
//# sourceMappingURL=generate-mipmaps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-mipmaps.js","names":["VS_GEN_MIPMAP","FS_GEN_MIPMAP","WebGPUMipmapGenerator","constructor","device","glslang","_defineProperty","mipmapSampler","createSampler","minFilter","mipmapPipeline","createRenderPipeline","vertexStage","module","createShaderModule","code","compileGLSL","entryPoint","fragmentStage","primitiveTopology","colorStates","format","generateMipmappedTexture","imageBitmap","textureSize","width","height","depth","mipLevelCount","Math","floor","log2","max","texture","createTexture","size","usage","GPUTextureUsage","COPY_DST","SAMPLED","OUTPUT_ATTACHMENT","queue","copyImageBitmapToTexture","srcTexture","commandEncoder","createCommandEncoder","i","passEncoder","beginRenderPass","colorAttachments","attachment","createView","baseMipLevel","loadValue","r","g","b","a","bindGroup","createBindGroup","layout","getBindGroupLayout","bindings","binding","resource","setPipeline","setBindGroup","draw","endPass","submit","finish"],"sources":["../../../src/adapter/helpers/generate-mipmaps.ts"],"sourcesContent":["// luma.gl, MIT license\n// Forked from Kangz/mipmapper.js under MIT license Copyright 2020 Brandon Jones\n// https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83\n\n// @ts-nocheck this is written against outdated WebGPU API, needs an update pass\n\nconst VS_GEN_MIPMAP = `\\#version 450\nconst vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));\nlayout(location = 0) out vec2 vTex;\nvoid main() {\n gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n vTex = gl_Position / 2.0f + vec2(0.5f);\n}`;\n\nconst FS_GEN_MIPMAP = `#version 450\nlayout(set = 0, binding = 0) uniform sampler imgSampler;\nlayout(set = 0, binding = 1) uniform texture2D img;\nlayout(location = 0) in vec2 vTex;\nlayout(location = 0) out vec4 outColor;\nvoid main() {\n outColor = texture(sampler2D(img, imgSampler), vTex);\n}`;\n\n/** WebGPU does not have built-in mipmap creation */\nexport class WebGPUMipmapGenerator {\n device: GPUDevice;\n mipmapSampler: GPUSampler;\n mipmapPipeline: GPURenderPipeline;\n\n constructor(device: GPUDevice, glslang) {\n this.device = device;\n\n this.mipmapSampler = device.createSampler({ minFilter: 'linear' });\n\n this.mipmapPipeline = device.createRenderPipeline({\n vertexStage: {\n module: device.createShaderModule({\n code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')\n }),\n entryPoint: 'main'\n },\n fragmentStage: {\n module: device.createShaderModule({\n code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')\n }),\n entryPoint: 'main'\n },\n primitiveTopology: 'triangle-strip',\n colorStates: [{\n format: 'rgba8unorm',\n }]\n });\n }\n\n generateMipmappedTexture(imageBitmap: ImageBitmap) {\n const textureSize = {\n width: imageBitmap.width,\n height: imageBitmap.height,\n depth: 1,\n }\n const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;\n\n // Populate the top level of the srcTexture with the imageBitmap.\n const texture = this.device.createTexture({\n size: textureSize,\n format: 'rgba8unorm',\n usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,\n mipLevelCount\n });\n this.device.queue.copyImageBitmapToTexture({ imageBitmap }, { texture: srcTexture }, textureSize);\n\n const commandEncoder = this.device.createCommandEncoder({});\n for (let i = 1; i < mipLevelCount; ++i) {\n const passEncoder = commandEncoder.beginRenderPass({\n colorAttachments: [{\n attachment: texture.createView({\n baseMipLevel: i,\n mipLevelCount: 1\n }),\n loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 },\n }],\n });\n\n const bindGroup = this.device.createBindGroup({\n layout: this.mipmapPipeline.getBindGroupLayout(0),\n bindings: [{\n binding: 0,\n resource: this.mipmapSampler,\n }, {\n binding: 1,\n resource: texture.createView({\n baseMipLevel: i - 1,\n mipLevelCount: 1\n }),\n }],\n });\n\n passEncoder.setPipeline(this.mipmapPipeline);\n passEncoder.setBindGroup(0, bindGroup);\n passEncoder.draw(4);\n passEncoder.endPass();\n }\n\n this.device.queue.submit([commandEncoder.finish()]);\n return texture;\n }\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAMvE;;;GAGG;
|
|
1
|
+
{"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAMvE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAM1H;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,eAAe,EAAE,kBAAkB,EACnC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,CAM/F"}
|
|
@@ -1,66 +1,51 @@
|
|
|
1
1
|
import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/api';
|
|
2
|
-
/**
|
|
3
|
-
* Create a WebGPU "bind group layout" from an array of luma.gl bindings
|
|
4
|
-
* @note bind groups can be automatically generated by WebGPU.
|
|
5
|
-
*/
|
|
6
2
|
export function makeBindGroupLayout(device, layout, bindings) {
|
|
7
|
-
|
|
8
|
-
// return device.createBindGroupLayout({
|
|
9
|
-
// layout,
|
|
10
|
-
// entries: getBindGroupEntries(bindings)
|
|
11
|
-
// })
|
|
3
|
+
throw new Error('not implemented');
|
|
12
4
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Create a WebGPU "bind group" from an array of luma.gl bindings
|
|
15
|
-
*/
|
|
16
5
|
export function getBindGroup(device, bindGroupLayout, layout, bindings) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const entries = getBindGroupEntries(bindings, layout);
|
|
7
|
+
return device.createBindGroup({
|
|
8
|
+
layout: bindGroupLayout,
|
|
9
|
+
entries
|
|
10
|
+
});
|
|
22
11
|
}
|
|
23
12
|
export function getShaderLayoutBinding(layout, bindingName) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
|
|
14
|
+
if (!bindingLayout) {
|
|
15
|
+
log.warn("Binding ".concat(bindingName, " not set: Not found in shader layout."))();
|
|
16
|
+
}
|
|
17
|
+
return bindingLayout;
|
|
29
18
|
}
|
|
30
|
-
/**
|
|
31
|
-
* @param bindings
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
19
|
function getBindGroupEntries(bindings, layout) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
20
|
+
const entries = [];
|
|
21
|
+
for (const [bindingName, value] of Object.entries(bindings)) {
|
|
22
|
+
const bindingLayout = getShaderLayoutBinding(layout, bindingName);
|
|
23
|
+
if (bindingLayout) {
|
|
24
|
+
entries.push(getBindGroupEntry(value, bindingLayout.location));
|
|
41
25
|
}
|
|
42
|
-
|
|
26
|
+
}
|
|
27
|
+
return entries;
|
|
43
28
|
}
|
|
44
29
|
function getBindGroupEntry(binding, index) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
throw new Error('invalid binding');
|
|
30
|
+
if (binding instanceof Buffer) {
|
|
31
|
+
return {
|
|
32
|
+
binding: index,
|
|
33
|
+
resource: {
|
|
34
|
+
buffer: cast(binding).handle
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (binding instanceof Sampler) {
|
|
39
|
+
return {
|
|
40
|
+
binding: index,
|
|
41
|
+
resource: cast(binding).handle
|
|
42
|
+
};
|
|
43
|
+
} else if (binding instanceof Texture) {
|
|
44
|
+
return {
|
|
45
|
+
binding: index,
|
|
46
|
+
resource: cast(binding).handle.createView()
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
throw new Error('invalid binding');
|
|
66
50
|
}
|
|
51
|
+
//# sourceMappingURL=get-bind-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-bind-group.js","names":["Buffer","Sampler","Texture","log","cast","makeBindGroupLayout","device","layout","bindings","Error","getBindGroup","bindGroupLayout","entries","getBindGroupEntries","createBindGroup","getShaderLayoutBinding","bindingName","bindingLayout","find","binding","name","warn","concat","value","Object","push","getBindGroupEntry","location","index","resource","buffer","handle","createView"],"sources":["../../../src/adapter/helpers/get-bind-group.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {ShaderLayout, BindingLayout, Binding} from '@luma.gl/api';\nimport {Buffer, Sampler, Texture, log, cast} from '@luma.gl/api';\nimport type WebGPUBuffer from '../resources/webgpu-buffer';\nimport type WebGPUSampler from '../resources/webgpu-sampler';\nimport type WebGPUTexture from '../resources/webgpu-texture';\n\n/**\n * Create a WebGPU \"bind group layout\" from an array of luma.gl bindings\n * @note bind groups can be automatically generated by WebGPU.\n */\nexport function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGroupLayout, bindings: Binding[]): GPUBindGroupLayout {\n throw new Error('not implemented');\n // return device.createBindGroupLayout({\n // layout,\n // entries: getBindGroupEntries(bindings)\n // })\n}\n\n/**\n * Create a WebGPU \"bind group\" from an array of luma.gl bindings\n */\nexport function getBindGroup(\n device: GPUDevice,\n bindGroupLayout: GPUBindGroupLayout,\n layout: ShaderLayout,\n bindings: Record<string, Binding>\n): GPUBindGroup {\n const entries = getBindGroupEntries(bindings, layout);\n return device.createBindGroup({\n layout: bindGroupLayout,\n entries\n });\n}\n\nexport function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout {\n const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);\n if (!bindingLayout) {\n log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();\n }\n return bindingLayout;\n}\n\n/**\n * @param bindings\n * @returns\n */\nfunction getBindGroupEntries(bindings: Record<string, Binding>, layout: ShaderLayout): GPUBindGroupEntry[] {\n const entries: GPUBindGroupEntry[] = [];\n\n for (const [bindingName, value] of Object.entries(bindings)) {\n const bindingLayout = getShaderLayoutBinding(layout, bindingName);\n if (bindingLayout) {\n entries.push(getBindGroupEntry(value, bindingLayout.location));\n }\n }\n\n return entries;\n}\n\nfunction getBindGroupEntry(binding: Binding, index: number): GPUBindGroupEntry {\n if (binding instanceof Buffer) {\n return {\n binding: index,\n resource: {\n buffer: cast<WebGPUBuffer>(binding).handle\n }\n };\n }\n if (binding instanceof Sampler) {\n return {\n binding: index,\n resource: cast<WebGPUSampler>(binding).handle\n };\n } else if (binding instanceof Texture) {\n return {\n binding: index,\n resource: cast<WebGPUTexture>(binding).handle.createView()\n };\n }\n throw new Error('invalid binding');\n}\n"],"mappings":"AAEA,SAAQA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,GAAG,EAAEC,IAAI,QAAO,cAAc;AAShE,OAAO,SAASC,mBAAmBA,CAACC,MAAiB,EAAEC,MAA0B,EAAEC,QAAmB,EAAsB;EAC1H,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;AAKpC;AAKA,OAAO,SAASC,YAAYA,CAC1BJ,MAAiB,EACjBK,eAAmC,EACnCJ,MAAoB,EACpBC,QAAiC,EACnB;EACd,MAAMI,OAAO,GAAGC,mBAAmB,CAACL,QAAQ,EAAED,MAAM,CAAC;EACrD,OAAOD,MAAM,CAACQ,eAAe,CAAC;IAC5BP,MAAM,EAAEI,eAAe;IACvBC;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,SAASG,sBAAsBA,CAACR,MAAoB,EAAES,WAAmB,EAAiB;EAC/F,MAAMC,aAAa,GAAGV,MAAM,CAACC,QAAQ,CAACU,IAAI,CAACC,OAAO,IAAIA,OAAO,CAACC,IAAI,KAAKJ,WAAW,CAAC;EACnF,IAAI,CAACC,aAAa,EAAE;IAClBd,GAAG,CAACkB,IAAI,YAAAC,MAAA,CAAYN,WAAW,2CAAwC,EAAE;EAC3E;EACA,OAAOC,aAAa;AACtB;AAMA,SAASJ,mBAAmBA,CAACL,QAAiC,EAAED,MAAoB,EAAuB;EACzG,MAAMK,OAA4B,GAAG,EAAE;EAEvC,KAAK,MAAM,CAACI,WAAW,EAAEO,KAAK,CAAC,IAAIC,MAAM,CAACZ,OAAO,CAACJ,QAAQ,CAAC,EAAE;IAC3D,MAAMS,aAAa,GAAGF,sBAAsB,CAACR,MAAM,EAAES,WAAW,CAAC;IACjE,IAAIC,aAAa,EAAE;MACjBL,OAAO,CAACa,IAAI,CAACC,iBAAiB,CAACH,KAAK,EAAEN,aAAa,CAACU,QAAQ,CAAC,CAAC;IAChE;EACF;EAEA,OAAOf,OAAO;AAChB;AAEA,SAASc,iBAAiBA,CAACP,OAAgB,EAAES,KAAa,EAAqB;EAC7E,IAAIT,OAAO,YAAYnB,MAAM,EAAE;IAC7B,OAAO;MACLmB,OAAO,EAAES,KAAK;MACdC,QAAQ,EAAE;QACRC,MAAM,EAAE1B,IAAI,CAAee,OAAO,CAAC,CAACY;MACtC;IACF,CAAC;EACH;EACA,IAAIZ,OAAO,YAAYlB,OAAO,EAAE;IAC9B,OAAO;MACLkB,OAAO,EAAES,KAAK;MACdC,QAAQ,EAAEzB,IAAI,CAAgBe,OAAO,CAAC,CAACY;IACzC,CAAC;EACH,CAAC,MAAM,IAAIZ,OAAO,YAAYjB,OAAO,EAAE;IACrC,OAAO;MACLiB,OAAO,EAAES,KAAK;MACdC,QAAQ,EAAEzB,IAAI,CAAgBe,OAAO,CAAC,CAACY,MAAM,CAACC,UAAU;IAC1D,CAAC;EACH;EACA,MAAM,IAAIvB,KAAK,CAAC,iBAAiB,CAAC;AACpC"}
|