@luma.gl/webgpu 9.0.0-beta.1 → 9.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) 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/get-bind-group.d.ts +3 -3
  5. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  6. package/dist/adapter/helpers/get-bind-group.js +57 -41
  7. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
  9. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  10. package/dist/adapter/helpers/webgpu-parameters.js +185 -125
  11. package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
  12. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgpu-buffer.js +119 -62
  14. package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
  15. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
  17. package/dist/adapter/resources/webgpu-compute-pass.d.ts +15 -9
  18. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  19. package/dist/adapter/resources/webgpu-compute-pass.js +76 -41
  20. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +14 -4
  21. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-compute-pipeline.js +46 -19
  23. package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
  24. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgpu-external-texture.js +35 -18
  26. package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
  27. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  28. package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
  29. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  30. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  31. package/dist/adapter/resources/webgpu-query-set.js +27 -0
  32. package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
  33. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgpu-render-pass.js +133 -105
  35. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +52 -5
  36. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  37. package/dist/adapter/resources/webgpu-render-pipeline.js +151 -78
  38. package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
  39. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgpu-sampler.js +21 -15
  41. package/dist/adapter/resources/webgpu-shader.d.ts +2 -5
  42. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  43. package/dist/adapter/resources/webgpu-shader.js +45 -44
  44. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  45. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  46. package/dist/adapter/resources/webgpu-texture-view.js +35 -0
  47. package/dist/adapter/resources/webgpu-texture.d.ts +8 -8
  48. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgpu-texture.js +130 -107
  50. package/dist/adapter/resources/webgpu-vertex-array.d.ts +9 -8
  51. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  52. package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
  53. package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
  54. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  55. package/dist/adapter/webgpu-canvas-context.js +101 -67
  56. package/dist/adapter/webgpu-device.d.ts +26 -28
  57. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  58. package/dist/adapter/webgpu-device.js +254 -220
  59. package/dist/dist.dev.js +804 -2270
  60. package/dist/dist.min.js +9 -0
  61. package/dist/index.cjs +366 -485
  62. package/dist/index.cjs.map +7 -0
  63. package/dist/index.d.ts +5 -5
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +5 -1
  66. package/dist.min.js +1 -22
  67. package/package.json +9 -7
  68. package/src/adapter/helpers/accessor-to-format.ts +5 -1
  69. package/src/adapter/helpers/convert-texture-format.ts +4 -1
  70. package/src/adapter/helpers/get-bind-group.ts +12 -6
  71. package/src/adapter/helpers/get-vertex-buffer-layout.ts +13 -5
  72. package/src/adapter/helpers/webgpu-parameters.ts +79 -15
  73. package/src/adapter/resources/webgpu-buffer.ts +24 -11
  74. package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
  75. package/src/adapter/resources/webgpu-compute-pass.ts +45 -22
  76. package/src/adapter/resources/webgpu-compute-pipeline.ts +48 -16
  77. package/src/adapter/resources/webgpu-external-texture.ts +14 -6
  78. package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
  79. package/src/adapter/resources/webgpu-query-set.ts +37 -0
  80. package/src/adapter/resources/webgpu-render-pass.ts +37 -14
  81. package/src/adapter/resources/webgpu-render-pipeline.ts +80 -119
  82. package/src/adapter/resources/webgpu-sampler.ts +4 -1
  83. package/src/adapter/resources/webgpu-shader.ts +14 -25
  84. package/src/adapter/resources/webgpu-texture-view.ts +46 -0
  85. package/src/adapter/resources/webgpu-texture.ts +33 -28
  86. package/src/adapter/resources/webgpu-vertex-array.ts +28 -20
  87. package/src/adapter/webgpu-canvas-context.ts +10 -4
  88. package/src/adapter/webgpu-device.ts +109 -106
  89. package/src/index.ts +2 -1
  90. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  91. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  92. package/dist/adapter/helpers/generate-mipmaps.d.ts +0 -10
  93. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
  94. package/dist/adapter/helpers/generate-mipmaps.js +0 -100
  95. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  96. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  97. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  98. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  99. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  100. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  101. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  102. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-query.d.ts +0 -1
  106. package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
  107. package/dist/adapter/resources/webgpu-query.js +0 -2
  108. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  110. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  111. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  112. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  113. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  114. package/dist/adapter/resources/webgpu-vertex-array.js.map +0 -1
  115. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  116. package/dist/adapter/webgpu-device.js.map +0 -1
  117. package/dist/adapter/webgpu-types.d.ts +0 -1
  118. package/dist/adapter/webgpu-types.d.ts.map +0 -1
  119. package/dist/adapter/webgpu-types.js +0 -2
  120. package/dist/adapter/webgpu-types.js.map +0 -1
  121. package/dist/glsl/glsllang.d.ts +0 -3
  122. package/dist/glsl/glsllang.d.ts.map +0 -1
  123. package/dist/glsl/glsllang.js +0 -9
  124. package/dist/glsl/glsllang.js.map +0 -1
  125. package/dist/index.js.map +0 -1
  126. package/src/adapter/helpers/generate-mipmaps.ts +0 -107
  127. package/src/adapter/resources/webgpu-query.ts +0 -43
  128. package/src/adapter/webgpu-types.ts +0 -0
  129. 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,5 +1,5 @@
1
1
  /// <reference types="dist" />
2
- import type { ShaderLayout, BindingDeclaration, Binding } from '@luma.gl/core';
2
+ import type { ComputeShaderLayout, BindingDeclaration, Binding } from '@luma.gl/core';
3
3
  /**
4
4
  * Create a WebGPU "bind group layout" from an array of luma.gl bindings
5
5
  * @note bind groups can be automatically generated by WebGPU.
@@ -8,6 +8,6 @@ export declare function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGr
8
8
  /**
9
9
  * Create a WebGPU "bind group" from an array of luma.gl bindings
10
10
  */
11
- export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, shaderLayout: ShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
12
- export declare function getShaderLayoutBinding(shaderLayout: ShaderLayout, bindingName: string): BindingDeclaration;
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,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,mBAAmB,EAAE,kBAAkB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAMpF;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,OAAO,EAAE,GAClB,kBAAkB,CAMpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,eAAe,EAAE,kBAAkB,EACnC,YAAY,EAAE,mBAAmB,EACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,mBAAmB,EACjC,WAAW,EAAE,MAAM,GAClB,kBAAkB,CASpB"}
@@ -1,53 +1,69 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/core';
5
+ /**
6
+ * Create a WebGPU "bind group layout" from an array of luma.gl bindings
7
+ * @note bind groups can be automatically generated by WebGPU.
8
+ */
2
9
  export function makeBindGroupLayout(device, layout, bindings) {
3
- 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);
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 || '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 || '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: stepMode || 'vertex',
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 || '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"}