@luma.gl/webgpu 9.0.0-beta.4 → 9.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +102 -1
  2. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.js +8 -5
  4. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -1
  5. package/dist/adapter/helpers/generate-mipmaps.js +85 -82
  6. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  7. package/dist/adapter/helpers/get-bind-group.js +57 -41
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  9. package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
  10. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  11. package/dist/adapter/helpers/webgpu-parameters.js +185 -125
  12. package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
  13. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-buffer.js +117 -62
  15. package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
  16. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
  18. package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
  19. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-compute-pass.js +71 -41
  21. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +1 -1
  22. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pipeline.js +28 -19
  24. package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
  25. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-external-texture.js +33 -18
  27. package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
  28. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
  30. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  31. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  32. package/dist/adapter/resources/webgpu-query-set.js +25 -0
  33. package/dist/adapter/resources/webgpu-query.js +42 -1
  34. package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
  35. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgpu-render-pass.js +133 -105
  37. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -4
  38. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  39. package/dist/adapter/resources/webgpu-render-pipeline.js +137 -80
  40. package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
  41. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgpu-sampler.js +18 -15
  43. package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
  44. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgpu-shader.js +56 -45
  46. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  47. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  48. package/dist/adapter/resources/webgpu-texture-view.js +32 -0
  49. package/dist/adapter/resources/webgpu-texture.d.ts +5 -4
  50. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgpu-texture.js +130 -107
  52. package/dist/adapter/resources/webgpu-vertex-array.d.ts +7 -6
  53. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  54. package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
  55. package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
  56. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  57. package/dist/adapter/webgpu-canvas-context.js +100 -67
  58. package/dist/adapter/webgpu-device.d.ts +24 -21
  59. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  60. package/dist/adapter/webgpu-device.js +264 -220
  61. package/dist/adapter/webgpu-types.js +0 -2
  62. package/dist/dist.dev.js +782 -2222
  63. package/dist/glsl/glsllang.js +9 -6
  64. package/dist/index.cjs +279 -388
  65. package/dist/index.cjs.map +7 -0
  66. package/dist/index.d.ts +5 -5
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +5 -1
  69. package/dist.min.js +1 -22
  70. package/package.json +9 -7
  71. package/src/adapter/helpers/accessor-to-format.ts +5 -1
  72. package/src/adapter/helpers/convert-texture-format.ts +4 -1
  73. package/src/adapter/helpers/generate-mipmaps.ts +37 -26
  74. package/src/adapter/helpers/get-bind-group.ts +8 -2
  75. package/src/adapter/helpers/get-vertex-buffer-layout.ts +12 -4
  76. package/src/adapter/helpers/webgpu-parameters.ts +79 -15
  77. package/src/adapter/resources/webgpu-buffer.ts +21 -10
  78. package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
  79. package/src/adapter/resources/webgpu-compute-pass.ts +26 -8
  80. package/src/adapter/resources/webgpu-compute-pipeline.ts +15 -10
  81. package/src/adapter/resources/webgpu-external-texture.ts +12 -6
  82. package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
  83. package/src/adapter/resources/webgpu-query-set.ts +35 -0
  84. package/src/adapter/resources/webgpu-render-pass.ts +37 -14
  85. package/src/adapter/resources/webgpu-render-pipeline.ts +30 -41
  86. package/src/adapter/resources/webgpu-sampler.ts +1 -1
  87. package/src/adapter/resources/webgpu-shader.ts +5 -4
  88. package/src/adapter/resources/webgpu-texture-view.ts +43 -0
  89. package/src/adapter/resources/webgpu-texture.ts +23 -19
  90. package/src/adapter/resources/webgpu-vertex-array.ts +25 -17
  91. package/src/adapter/webgpu-canvas-context.ts +8 -3
  92. package/src/adapter/webgpu-device.ts +100 -88
  93. package/src/index.ts +2 -1
  94. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  95. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  96. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  97. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  98. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  99. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  100. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  101. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  102. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  106. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  107. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  108. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  110. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  111. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  112. package/dist/adapter/resources/webgpu-vertex-array.js.map +0 -1
  113. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  114. package/dist/adapter/webgpu-device.js.map +0 -1
  115. package/dist/adapter/webgpu-types.js.map +0 -1
  116. package/dist/glsl/glsllang.js.map +0 -1
  117. package/dist/index.js.map +0 -1
  118. package/src/adapter/resources/webgpu-query.ts +0 -43
  119. package/src/adapter/webgpu-types.ts +0 -0
  120. 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
- //# sourceMappingURL=accessor-to-format.js.map
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":";AACA,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAE5C,mDAAmD;AACnD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAK9E"}
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
- if (format.includes('webgl')) {
3
- throw new Error('webgl-only format');
4
- }
5
- return format;
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 +1 @@
1
- {"version":3,"file":"generate-mipmaps.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/generate-mipmaps.ts"],"names":[],"mappings":";AAuBA,oDAAoD;AACpD,qBAAa,qBAAqB;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,iBAAiB,CAAC;gBAEtB,MAAM,EAAE,SAAS,EAAE,OAAO,KAAA;IAyBtC,wBAAwB,CAAC,WAAW,EAAE,WAAW;CAoDlD"}
1
+ {"version":3,"file":"generate-mipmaps.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/generate-mipmaps.ts"],"names":[],"mappings":";AA0BA,oDAAoD;AACpD,qBAAa,qBAAqB;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,iBAAiB,CAAC;gBAEtB,MAAM,EAAE,SAAS,EAAE,OAAO,KAAA;IA2BtC,wBAAwB,CAAC,WAAW,EAAE,WAAW;CA0DlD"}
@@ -1,3 +1,9 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from Kangz/mipmapper.js under MIT license Copyright 2020 Brandon Jones
5
+ // https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83
6
+ // @ts-nocheck this is written against outdated WebGPU API, needs an update pass
1
7
  const VS_GEN_MIPMAP = `\#version 450
2
8
  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));
3
9
  layout(location = 0) out vec2 vTex;
@@ -13,88 +19,85 @@ layout(location = 0) out vec4 outColor;
13
19
  void main() {
14
20
  outColor = texture(sampler2D(img, imgSampler), vTex);
15
21
  }`;
22
+ /** WebGPU does not have built-in mipmap creation */
16
23
  export class WebGPUMipmapGenerator {
17
- constructor(device, glslang) {
18
- this.device = void 0;
19
- this.mipmapSampler = void 0;
20
- this.mipmapPipeline = void 0;
21
- this.device = device;
22
- this.mipmapSampler = device.createSampler({
23
- minFilter: 'linear'
24
- });
25
- this.mipmapPipeline = device.createRenderPipeline({
26
- vertexStage: {
27
- module: device.createShaderModule({
28
- code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')
29
- }),
30
- entryPoint: 'main'
31
- },
32
- fragmentStage: {
33
- module: device.createShaderModule({
34
- code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')
35
- }),
36
- entryPoint: 'main'
37
- },
38
- primitiveTopology: 'triangle-strip',
39
- colorStates: [{
40
- format: 'rgba8unorm'
41
- }]
42
- });
43
- }
44
- generateMipmappedTexture(imageBitmap) {
45
- const textureSize = {
46
- width: imageBitmap.width,
47
- height: imageBitmap.height,
48
- depth: 1
49
- };
50
- const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
51
- const texture = this.device.createTexture({
52
- size: textureSize,
53
- format: 'rgba8unorm',
54
- usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
55
- mipLevelCount
56
- });
57
- this.device.queue.copyImageBitmapToTexture({
58
- imageBitmap
59
- }, {
60
- texture
61
- }, textureSize);
62
- const commandEncoder = this.device.createCommandEncoder({});
63
- for (let i = 1; i < mipLevelCount; ++i) {
64
- const passEncoder = commandEncoder.beginRenderPass({
65
- colorAttachments: [{
66
- attachment: texture.createView({
67
- baseMipLevel: i,
68
- mipLevelCount: 1
69
- }),
70
- loadValue: {
71
- r: 1.0,
72
- g: 0.0,
73
- b: 0.0,
74
- a: 0.0
75
- }
76
- }]
77
- });
78
- const bindGroup = this.device.createBindGroup({
79
- layout: this.mipmapPipeline.getBindGroupLayout(0),
80
- bindings: [{
81
- binding: 0,
82
- resource: this.mipmapSampler
83
- }, {
84
- binding: 1,
85
- resource: texture.createView({
86
- baseMipLevel: i - 1,
87
- mipLevelCount: 1
88
- })
89
- }]
90
- });
91
- passEncoder.setPipeline(this.mipmapPipeline);
92
- passEncoder.setBindGroup(0, bindGroup);
93
- passEncoder.draw(4);
94
- passEncoder.endPass();
24
+ device;
25
+ mipmapSampler;
26
+ mipmapPipeline;
27
+ constructor(device, glslang) {
28
+ this.device = device;
29
+ this.mipmapSampler = device.createSampler({ minFilter: 'linear' });
30
+ this.mipmapPipeline = device.createRenderPipeline({
31
+ vertexStage: {
32
+ module: device.createShaderModule({
33
+ code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')
34
+ }),
35
+ entryPoint: 'main'
36
+ },
37
+ fragmentStage: {
38
+ module: device.createShaderModule({
39
+ code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')
40
+ }),
41
+ entryPoint: 'main'
42
+ },
43
+ primitiveTopology: 'triangle-strip',
44
+ colorStates: [
45
+ {
46
+ format: 'rgba8unorm'
47
+ }
48
+ ]
49
+ });
50
+ }
51
+ generateMipmappedTexture(imageBitmap) {
52
+ const textureSize = {
53
+ width: imageBitmap.width,
54
+ height: imageBitmap.height,
55
+ depth: 1
56
+ };
57
+ const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
58
+ // Populate the top level of the srcTexture with the imageBitmap.
59
+ const texture = this.device.createTexture({
60
+ size: textureSize,
61
+ format: 'rgba8unorm',
62
+ usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
63
+ mipLevelCount
64
+ });
65
+ this.device.queue.copyImageBitmapToTexture({ imageBitmap }, { texture }, textureSize);
66
+ const commandEncoder = this.device.createCommandEncoder({});
67
+ for (let i = 1; i < mipLevelCount; ++i) {
68
+ const passEncoder = commandEncoder.beginRenderPass({
69
+ colorAttachments: [
70
+ {
71
+ attachment: texture.createView({
72
+ baseMipLevel: i,
73
+ mipLevelCount: 1
74
+ }),
75
+ loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 }
76
+ }
77
+ ]
78
+ });
79
+ const bindGroup = this.device.createBindGroup({
80
+ layout: this.mipmapPipeline.getBindGroupLayout(0),
81
+ bindings: [
82
+ {
83
+ binding: 0,
84
+ resource: this.mipmapSampler
85
+ },
86
+ {
87
+ binding: 1,
88
+ resource: texture.createView({
89
+ baseMipLevel: i - 1,
90
+ mipLevelCount: 1
91
+ })
92
+ }
93
+ ]
94
+ });
95
+ passEncoder.setPipeline(this.mipmapPipeline);
96
+ passEncoder.setBindGroup(0, bindGroup);
97
+ passEncoder.draw(4);
98
+ passEncoder.endPass();
99
+ }
100
+ this.device.queue.submit([commandEncoder.finish()]);
101
+ return texture;
95
102
  }
96
- this.device.queue.submit([commandEncoder.finish()]);
97
- return texture;
98
- }
99
103
  }
100
- //# sourceMappingURL=generate-mipmaps.js.map
@@ -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,kBAAkB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAM7E;;;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,YAAY,EAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,MAAM,GAClB,kBAAkB,CAMpB"}
1
+ {"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAM7E;;;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,YAAY,EAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,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
- throw new Error('not implemented');
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
- const entries = getBindGroupEntries(bindings, shaderLayout);
7
- return device.createBindGroup({
8
- layout: bindGroupLayout,
9
- entries
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
- const bindingLayout = shaderLayout.bindings.find(binding => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
14
- if (!bindingLayout) {
15
- log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
16
- }
17
- return bindingLayout;
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
- const entries = [];
21
- for (const [bindingName, value] of Object.entries(bindings)) {
22
- const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
23
- if (bindingLayout) {
24
- entries.push(getBindGroupEntry(value, bindingLayout.location));
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
- 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
- label: 'bind-group-auto-created'
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":";AACA,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,CAuEzB;AAED,wBAAgB,cAAc,CAC5B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BxB"}
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
- if (format.endsWith('-webgl')) {
4
- throw new Error(`WebGPU does not support vertex format ${format}`);
5
- }
6
- return format;
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
- const vertexBufferLayouts = [];
10
- const usedAttributes = new Set();
11
- for (const mapping of bufferLayout) {
12
- const vertexAttributes = [];
13
- let stepMode = 'vertex';
14
- let byteStride = 0;
15
- if (mapping.attributes) {
16
- for (const attributeMapping of mapping.attributes) {
17
- const attributeName = attributeMapping.attribute;
18
- const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
19
- stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
20
- vertexAttributes.push({
21
- format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
22
- offset: attributeMapping.byteOffset,
23
- shaderLocation: attributeLayout.location
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 || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
34
- vertexAttributes.push({
35
- format: getWebGPUVertexFormat(mapping.format),
36
- offset: 0,
37
- shaderLocation: attributeLayout.location
38
- });
39
70
  }
40
- vertexBufferLayouts.push({
41
- arrayStride: mapping.byteStride || byteStride,
42
- stepMode,
43
- attributes: vertexAttributes
44
- });
45
- }
46
- for (const attribute of shaderLayout.attributes) {
47
- if (!usedAttributes.has(attribute.name)) {
48
- vertexBufferLayouts.push({
49
- arrayStride: decodeVertexFormat('float32x3').byteLength,
50
- stepMode: attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'),
51
- attributes: [{
52
- format: getWebGPUVertexFormat('float32x3'),
53
- offset: 0,
54
- shaderLocation: attribute.location
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
- const usedAttributes = new Set();
63
- let bufferSlot = 0;
64
- const bufferSlots = {};
65
- for (const mapping of bufferLayout) {
66
- if ('attributes' in mapping) {
67
- for (const interleaved of mapping.attributes) {
68
- usedAttributes.add(interleaved.attribute);
69
- }
70
- } else {
71
- usedAttributes.add(mapping.name);
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
- bufferSlots[mapping.name] = bufferSlot++;
74
- }
75
- for (const attribute of shaderLayout.attributes) {
76
- if (!usedAttributes.has(attribute.name)) {
77
- bufferSlots[attribute.name] = bufferSlot++;
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
- const attribute = shaderLayout.attributes.find(attribute => attribute.name === name);
84
- if (!attribute) {
85
- log.warn(`Unknown attribute ${name}`)();
86
- return null;
87
- }
88
- if (attributeNames.has(name)) {
89
- throw new Error(`Duplicate attribute ${name}`);
90
- }
91
- attributeNames.add(name);
92
- return attribute;
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":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAezC;;;GAGG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAsJ9D,CAAC;AAgCF,wBAAgB,yCAAyC,CACvD,kBAAkB,EAAE,2BAA2B,EAC/C,UAAU,GAAE,UAAe,GAC1B,IAAI,CAIN"}
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"}