@luma.gl/webgpu 9.0.0-alpha.9 → 9.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/helpers/accessor-to-format.js +102 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
  4. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  5. package/dist/adapter/helpers/convert-texture-format.js +8 -6
  6. package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
  7. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  8. package/dist/adapter/helpers/get-bind-group.js +61 -52
  9. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
  10. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-vertex-buffer-layout.js +123 -90
  12. package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
  13. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  14. package/dist/adapter/helpers/webgpu-parameters.js +184 -130
  15. package/dist/adapter/resources/webgpu-buffer.d.ts +14 -5
  16. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-buffer.js +117 -70
  18. package/dist/adapter/resources/webgpu-command-encoder.d.ts +13 -14
  19. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-command-encoder.js +83 -65
  21. package/dist/adapter/resources/webgpu-compute-pass.d.ts +19 -13
  22. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pass.js +78 -57
  24. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +16 -6
  25. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-compute-pipeline.js +48 -26
  27. package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
  28. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-external-texture.js +38 -29
  30. package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
  31. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgpu-framebuffer.js +15 -109
  33. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  34. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  35. package/dist/adapter/resources/webgpu-query-set.js +27 -0
  36. package/dist/adapter/resources/webgpu-render-pass.d.ts +14 -7
  37. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-render-pass.js +136 -91
  39. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +63 -23
  40. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgpu-render-pipeline.js +151 -148
  42. package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
  43. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-sampler.js +23 -23
  45. package/dist/adapter/resources/webgpu-shader.d.ts +9 -12
  46. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgpu-shader.js +47 -60
  48. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  49. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  50. package/dist/adapter/resources/webgpu-texture-view.js +35 -0
  51. package/dist/adapter/resources/webgpu-texture.d.ts +20 -10
  52. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-texture.js +133 -105
  54. package/dist/adapter/resources/webgpu-vertex-array.d.ts +27 -0
  55. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  56. package/dist/adapter/resources/webgpu-vertex-array.js +66 -0
  57. package/dist/adapter/webgpu-canvas-context.d.ts +17 -12
  58. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  59. package/dist/adapter/webgpu-canvas-context.js +105 -92
  60. package/dist/adapter/webgpu-device.d.ts +45 -30
  61. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  62. package/dist/adapter/webgpu-device.js +266 -241
  63. package/dist/dist.dev.js +1664 -0
  64. package/dist/dist.min.js +9 -0
  65. package/dist/index.cjs +1432 -0
  66. package/dist/index.cjs.map +7 -0
  67. package/dist/index.d.ts +5 -7
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +10 -8
  70. package/dist.min.js +9 -0
  71. package/package.json +22 -11
  72. package/src/adapter/helpers/accessor-to-format.ts +6 -3
  73. package/src/adapter/helpers/convert-texture-format.ts +5 -2
  74. package/src/adapter/helpers/get-bind-group.ts +30 -14
  75. package/src/adapter/helpers/get-vertex-buffer-layout.ts +73 -39
  76. package/src/adapter/helpers/webgpu-parameters.ts +99 -29
  77. package/src/adapter/resources/webgpu-buffer.ts +85 -17
  78. package/src/adapter/resources/webgpu-command-encoder.ts +93 -58
  79. package/src/adapter/resources/webgpu-compute-pass.ts +56 -32
  80. package/src/adapter/resources/webgpu-compute-pipeline.ts +51 -18
  81. package/src/adapter/resources/webgpu-external-texture.ts +19 -11
  82. package/src/adapter/resources/webgpu-framebuffer.ts +11 -108
  83. package/src/adapter/resources/webgpu-query-set.ts +37 -0
  84. package/src/adapter/resources/webgpu-render-pass.ts +95 -19
  85. package/src/adapter/resources/webgpu-render-pipeline.ts +139 -159
  86. package/src/adapter/resources/webgpu-sampler.ts +10 -7
  87. package/src/adapter/resources/webgpu-shader.ts +30 -35
  88. package/src/adapter/resources/webgpu-texture-view.ts +46 -0
  89. package/src/adapter/resources/webgpu-texture.ts +75 -41
  90. package/src/adapter/resources/webgpu-vertex-array.ts +91 -0
  91. package/src/adapter/webgpu-canvas-context.ts +60 -29
  92. package/src/adapter/webgpu-device.ts +219 -120
  93. package/src/index.ts +8 -9
  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.d.ts +0 -10
  97. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
  98. package/dist/adapter/helpers/generate-mipmaps.js +0 -95
  99. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  100. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  101. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  102. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  106. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  107. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  108. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-query.d.ts +0 -1
  110. package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
  111. package/dist/adapter/resources/webgpu-query.js +0 -2
  112. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  113. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  114. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  115. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  116. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  117. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  118. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  119. package/dist/adapter/webgpu-device.js.map +0 -1
  120. package/dist/adapter/webgpu-types.d.ts +0 -1
  121. package/dist/adapter/webgpu-types.d.ts.map +0 -1
  122. package/dist/adapter/webgpu-types.js +0 -2
  123. package/dist/adapter/webgpu-types.js.map +0 -1
  124. package/dist/bundle.d.ts +0 -2
  125. package/dist/bundle.d.ts.map +0 -1
  126. package/dist/bundle.js +0 -5
  127. package/dist/bundle.js.map +0 -1
  128. package/dist/glsl/glsllang.d.ts +0 -3
  129. package/dist/glsl/glsllang.d.ts.map +0 -1
  130. package/dist/glsl/glsllang.js +0 -10
  131. package/dist/glsl/glsllang.js.map +0 -1
  132. package/dist/index.js.map +0 -1
  133. package/dist/init.d.ts +0 -2
  134. package/dist/init.d.ts.map +0 -1
  135. package/dist/init.js +0 -4
  136. package/dist/init.js.map +0 -1
  137. package/src/adapter/helpers/generate-mipmaps.ts +0 -107
  138. package/src/adapter/resources/webgpu-query.ts +0 -43
  139. package/src/adapter/webgpu-types.ts +0 -0
  140. package/src/bundle.ts +0 -4
  141. package/src/glsl/glsllang.ts +0 -14
  142. package/src/init.ts +0 -4
package/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2020 Urban Computing Foundation
1
+ luma.gl is provided under the MIT license
2
+
3
+ Copyright (c) 2020 vis.gl contributors
2
4
 
3
5
  This software includes parts initially developed by Uber and open sourced under MIT license.
4
6
  Copyright (c) 2015 Uber Technologies, Inc.
@@ -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,5 +1,5 @@
1
- /// <reference types="@webgpu/types" />
2
- import { TextureFormat } from '@luma.gl/api';
1
+ /// <reference types="dist" />
2
+ import { TextureFormat } from '@luma.gl/core';
3
3
  /** Ensure a texture format is WebGPU compatible */
4
4
  export declare function getWebGPUTextureFormat(format: TextureFormat): GPUTextureFormat;
5
5
  //# sourceMappingURL=convert-texture-format.d.ts.map
@@ -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,cAAc,CAAC;AAE3C,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,8 +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
-
6
- return format;
6
+ if (format.includes('webgl')) {
7
+ throw new Error('webgl-only format');
8
+ }
9
+ return format;
7
10
  }
8
- //# sourceMappingURL=convert-texture-format.js.map
@@ -1,5 +1,5 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { ShaderLayout, BindingLayout, Binding } from '@luma.gl/api';
1
+ /// <reference types="dist" />
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, layout: ShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
12
- export declare function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout;
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":";AACA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAMvE;;;GAGG;AACF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAM3H;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
+ {"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,60 +1,69 @@
1
- import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/api';
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
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
  }
5
- export function getBindGroup(device, bindGroupLayout, layout, bindings) {
6
- const entries = getBindGroupEntries(bindings, layout);
7
- return device.createBindGroup({
8
- layout: bindGroupLayout,
9
- entries
10
- });
16
+ /**
17
+ * Create a WebGPU "bind group" from an array of luma.gl bindings
18
+ */
19
+ export function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
20
+ const entries = getBindGroupEntries(bindings, shaderLayout);
21
+ return device.createBindGroup({
22
+ layout: bindGroupLayout,
23
+ entries
24
+ });
11
25
  }
12
- export function getShaderLayoutBinding(layout, bindingName) {
13
- const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
14
-
15
- if (!bindingLayout) {
16
- log.warn("Binding ".concat(bindingName, " not set: Not found in shader layout."))();
17
- }
18
-
19
- return bindingLayout;
26
+ export function getShaderLayoutBinding(shaderLayout, bindingName) {
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;
20
32
  }
21
-
22
- function getBindGroupEntries(bindings, layout) {
23
- const entries = [];
24
-
25
- for (const [bindingName, value] of Object.entries(bindings)) {
26
- const bindingLayout = getShaderLayoutBinding(layout, bindingName);
27
-
28
- if (bindingLayout) {
29
- entries.push(getBindGroupEntry(value, bindingLayout.location));
33
+ /**
34
+ * @param bindings
35
+ * @returns
36
+ */
37
+ function getBindGroupEntries(bindings, shaderLayout) {
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
+ }
30
44
  }
31
- }
32
-
33
- return entries;
45
+ return entries;
34
46
  }
35
-
36
47
  function getBindGroupEntry(binding, index) {
37
- if (binding instanceof Buffer) {
38
- return {
39
- binding: index,
40
- resource: {
41
- buffer: cast(binding).handle
42
- }
43
- };
44
- }
45
-
46
- if (binding instanceof Sampler) {
47
- return {
48
- binding: index,
49
- resource: cast(binding).handle
50
- };
51
- } else if (binding instanceof Texture) {
52
- return {
53
- binding: index,
54
- resource: cast(binding).handle.createView()
55
- };
56
- }
57
-
58
- 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');
59
69
  }
60
- //# sourceMappingURL=get-bind-group.js.map
@@ -1,12 +1,12 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { ShaderLayout, BufferMapping } from '@luma.gl/api';
1
+ /// <reference types="dist" />
2
+ import type { ShaderLayout, BufferLayout } from '@luma.gl/core';
3
3
  /**
4
4
  * Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.
5
5
  * Converts luma.gl attribute definitions to a WebGPU GPUVertexBufferLayout[] array
6
6
  * @param layout
7
- * @param bufferMap The buffer map is optional
7
+ * @param bufferLayout The buffer map is optional
8
8
  * @returns WebGPU layout intended for a GPURenderPassDescriptor.
9
9
  */
10
- export declare function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMapping[]): GPUVertexBufferLayout[];
11
- export declare function getBufferSlots(layout: ShaderLayout, bufferMap: BufferMapping[]): Record<string, number>;
10
+ export declare function getVertexBufferLayout(shaderLayout: ShaderLayout, bufferLayout: BufferLayout[]): GPUVertexBufferLayout[];
11
+ export declare function getBufferSlots(shaderLayout: ShaderLayout, bufferLayout: BufferLayout[]): Record<string, number>;
12
12
  //# sourceMappingURL=get-vertex-buffer-layout.d.ts.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":";AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;AAG/E;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,qBAAqB,EAAE,CAkE/G;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BvG"}
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,98 +1,131 @@
1
- import { decodeVertexFormat } from '@luma.gl/api';
2
- export function getVertexBufferLayout(layout, bufferMap) {
3
- const vertexBufferLayouts = [];
4
- const usedAttributes = new Set();
5
-
6
- for (const mapping of bufferMap) {
7
- const vertexAttributes = [];
8
- let stepMode = 'vertex';
9
- let byteStride = 0;
10
- let byteOffset = mapping.byteOffset || 0;
11
-
12
- if ('attributes' in mapping) {
13
- const arrayStride = mapping.byteStride;
14
-
15
- for (const interleaved of mapping.attributes) {
16
- const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
17
- stepMode = attributeLayout.stepMode || 'vertex';
18
- vertexAttributes.push({
19
- format: attributeLayout.format,
20
- offset: byteOffset + byteStride,
21
- shaderLocation: attributeLayout.location
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { log, decodeVertexFormat } from '@luma.gl/core';
5
+ // import {getAttributeInfosFromLayouts} from '@luma.gl/core';
6
+ /** Throw error on any WebGL-only vertex formats */
7
+ function getWebGPUVertexFormat(format) {
8
+ if (format.endsWith('-webgl')) {
9
+ throw new Error(`WebGPU does not support vertex format ${format}`);
10
+ }
11
+ return format;
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
+ */
20
+ export function getVertexBufferLayout(shaderLayout, bufferLayout) {
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
22
69
  });
23
- byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
24
- }
25
- } else {
26
- const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
27
- byteStride = decodeVertexFormat(attributeLayout.format).byteLength, stepMode = attributeLayout.stepMode || 'vertex';
28
- vertexAttributes.push({
29
- format: attributeLayout.format,
30
- offset: byteOffset,
31
- shaderLocation: attributeLayout.location
32
- });
33
70
  }
34
-
35
- vertexBufferLayouts.push({
36
- arrayStride: mapping.byteStride || byteStride,
37
- stepMode: stepMode || 'vertex',
38
- attributes: vertexAttributes
39
- });
40
- }
41
-
42
- for (const attribute of layout.attributes) {
43
- if (!usedAttributes.has(attribute.name)) {
44
- vertexBufferLayouts.push({
45
- arrayStride: decodeVertexFormat(attribute.format).byteLength,
46
- stepMode: attribute.stepMode || 'vertex',
47
- attributes: [{
48
- format: attribute.format,
49
- offset: 0,
50
- shaderLocation: attribute.location
51
- }]
52
- });
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
+ }
53
86
  }
54
- }
55
-
56
- return vertexBufferLayouts;
87
+ return vertexBufferLayouts;
57
88
  }
58
- export function getBufferSlots(layout, bufferMap) {
59
- const usedAttributes = new Set();
60
- let bufferSlot = 0;
61
- const bufferSlots = {};
62
-
63
- for (const mapping of bufferMap) {
64
- if ('attributes' in mapping) {
65
- for (const interleaved of mapping.attributes) {
66
- usedAttributes.add(interleaved.name);
67
- }
68
- } else {
69
- usedAttributes.add(mapping.name);
89
+ export function getBufferSlots(shaderLayout, bufferLayout) {
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++;
70
106
  }
71
-
72
- bufferSlots[mapping.name] = bufferSlot++;
73
- }
74
-
75
- for (const attribute of layout.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
-
81
- return bufferSlots;
113
+ return bufferSlots;
82
114
  }
83
-
84
- function findAttributeLayout(layout, name, attributeNames) {
85
- const attribute = layout.attributes.find(attribute => attribute.name === name);
86
-
87
- if (!attribute) {
88
- throw new Error("Unknown attribute ".concat(name));
89
- }
90
-
91
- if (attributeNames.has(name)) {
92
- throw new Error("Duplicate attribute ".concat(name));
93
- }
94
-
95
- attributeNames.add(name);
96
- return attribute;
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
+ */
120
+ function findAttributeLayout(shaderLayout, name, attributeNames) {
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;
97
131
  }
98
- //# sourceMappingURL=get-vertex-buffer-layout.js.map
@@ -1,5 +1,5 @@
1
- /// <reference types="@webgpu/types" />
2
- import { Parameters } from '@luma.gl/api';
1
+ /// <reference types="dist" />
2
+ import { Parameters } from '@luma.gl/core';
3
3
  /**
4
4
  * Supports for luma.gl's flat parameter space
5
5
  * Populates the corresponding sub-objects in a GPURenderPipelineDescriptor
@@ -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,cAAc,CAAC;AAYxC;;;GAGG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAqJ9D,CAAC;AA8BF,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"}