@luma.gl/webgpu 9.0.0-alpha.15 → 9.0.0-alpha.16

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 (179) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +100 -1
  2. package/dist/adapter/helpers/convert-texture-format.js +5 -6
  3. package/dist/adapter/helpers/generate-mipmaps.js +88 -92
  4. package/dist/adapter/helpers/get-bind-group.js +54 -48
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.js +97 -84
  6. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  7. package/dist/adapter/helpers/webgpu-parameters.js +181 -129
  8. package/dist/adapter/resources/webgpu-buffer.js +57 -73
  9. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-command-encoder.js +47 -63
  11. package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
  12. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgpu-compute-pass.js +51 -55
  14. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-compute-pipeline.js +22 -24
  16. package/dist/adapter/resources/webgpu-external-texture.js +26 -27
  17. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgpu-framebuffer.js +89 -103
  19. package/dist/adapter/resources/webgpu-query.js +42 -1
  20. package/dist/adapter/resources/webgpu-render-pass.d.ts +1 -1
  21. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-render-pass.js +64 -89
  23. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-render-pipeline.js +158 -154
  25. package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
  26. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgpu-sampler.js +16 -22
  28. package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
  29. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-shader.js +47 -58
  31. package/dist/adapter/resources/webgpu-texture.d.ts +0 -1
  32. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgpu-texture.js +100 -103
  34. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  35. package/dist/adapter/webgpu-canvas-context.js +77 -90
  36. package/dist/adapter/webgpu-device.js +215 -242
  37. package/dist/adapter/webgpu-types.js +0 -2
  38. package/dist/bundle.js +1 -2
  39. package/dist/dist.js +8051 -0
  40. package/dist/dist.min.js +1 -0
  41. package/dist/es5/adapter/helpers/accessor-to-format.js +2 -0
  42. package/dist/es5/adapter/helpers/accessor-to-format.js.map +1 -0
  43. package/dist/es5/adapter/helpers/convert-texture-format.js +13 -0
  44. package/dist/es5/adapter/helpers/convert-texture-format.js.map +1 -0
  45. package/dist/es5/adapter/helpers/generate-mipmaps.js +103 -0
  46. package/dist/es5/adapter/helpers/generate-mipmaps.js.map +1 -0
  47. package/dist/es5/adapter/helpers/get-bind-group.js +66 -0
  48. package/dist/es5/adapter/helpers/get-bind-group.js.map +1 -0
  49. package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js +149 -0
  50. package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  51. package/dist/es5/adapter/helpers/webgpu-parameters.js +150 -0
  52. package/dist/es5/adapter/helpers/webgpu-parameters.js.map +1 -0
  53. package/dist/es5/adapter/resources/webgpu-buffer.js +131 -0
  54. package/dist/es5/adapter/resources/webgpu-buffer.js.map +1 -0
  55. package/dist/es5/adapter/resources/webgpu-command-encoder.js +90 -0
  56. package/dist/es5/adapter/resources/webgpu-command-encoder.js.map +1 -0
  57. package/dist/es5/adapter/resources/webgpu-compute-pass.js +85 -0
  58. package/dist/es5/adapter/resources/webgpu-compute-pass.js.map +1 -0
  59. package/dist/es5/adapter/resources/webgpu-compute-pipeline.js +48 -0
  60. package/dist/es5/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
  61. package/dist/es5/adapter/resources/webgpu-external-texture.js +50 -0
  62. package/dist/es5/adapter/resources/webgpu-external-texture.js.map +1 -0
  63. package/dist/es5/adapter/resources/webgpu-framebuffer.js +126 -0
  64. package/dist/es5/adapter/resources/webgpu-framebuffer.js.map +1 -0
  65. package/dist/es5/adapter/resources/webgpu-query.js +2 -0
  66. package/dist/es5/adapter/resources/webgpu-query.js.map +1 -0
  67. package/dist/es5/adapter/resources/webgpu-render-pass.js +124 -0
  68. package/dist/es5/adapter/resources/webgpu-render-pass.js.map +1 -0
  69. package/dist/es5/adapter/resources/webgpu-render-pipeline.js +185 -0
  70. package/dist/es5/adapter/resources/webgpu-render-pipeline.js.map +1 -0
  71. package/dist/es5/adapter/resources/webgpu-sampler.js +45 -0
  72. package/dist/es5/adapter/resources/webgpu-sampler.js.map +1 -0
  73. package/dist/es5/adapter/resources/webgpu-shader.js +125 -0
  74. package/dist/es5/adapter/resources/webgpu-shader.js.map +1 -0
  75. package/dist/es5/adapter/resources/webgpu-texture.js +138 -0
  76. package/dist/es5/adapter/resources/webgpu-texture.js.map +1 -0
  77. package/dist/es5/adapter/webgpu-canvas-context.js +111 -0
  78. package/dist/es5/adapter/webgpu-canvas-context.js.map +1 -0
  79. package/dist/es5/adapter/webgpu-device.js +317 -0
  80. package/dist/es5/adapter/webgpu-device.js.map +1 -0
  81. package/dist/es5/adapter/webgpu-types.js +2 -0
  82. package/dist/es5/adapter/webgpu-types.js.map +1 -0
  83. package/dist/es5/bundle.js +6 -0
  84. package/dist/es5/bundle.js.map +1 -0
  85. package/dist/es5/glsl/glsllang.js +47 -0
  86. package/dist/es5/glsl/glsllang.js.map +1 -0
  87. package/dist/es5/index.js +44 -0
  88. package/dist/es5/index.js.map +1 -0
  89. package/dist/es5/init.js +7 -0
  90. package/dist/es5/init.js.map +1 -0
  91. package/dist/esm/adapter/helpers/accessor-to-format.js +2 -0
  92. package/dist/esm/adapter/helpers/accessor-to-format.js.map +1 -0
  93. package/dist/esm/adapter/helpers/convert-texture-format.js +7 -0
  94. package/dist/esm/adapter/helpers/convert-texture-format.js.map +1 -0
  95. package/dist/esm/adapter/helpers/generate-mipmaps.js +88 -0
  96. package/dist/esm/adapter/helpers/generate-mipmaps.js.map +1 -0
  97. package/dist/esm/adapter/helpers/get-bind-group.js +51 -0
  98. package/dist/esm/adapter/helpers/get-bind-group.js.map +1 -0
  99. package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js +83 -0
  100. package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  101. package/dist/esm/adapter/helpers/webgpu-parameters.js +137 -0
  102. package/dist/esm/adapter/helpers/webgpu-parameters.js.map +1 -0
  103. package/dist/esm/adapter/resources/webgpu-buffer.js +70 -0
  104. package/dist/esm/adapter/resources/webgpu-buffer.js.map +1 -0
  105. package/dist/esm/adapter/resources/webgpu-command-encoder.js +49 -0
  106. package/dist/esm/adapter/resources/webgpu-command-encoder.js.map +1 -0
  107. package/dist/esm/adapter/resources/webgpu-compute-pass.js +44 -0
  108. package/dist/esm/adapter/resources/webgpu-compute-pass.js.map +1 -0
  109. package/dist/esm/adapter/resources/webgpu-compute-pipeline.js +23 -0
  110. package/dist/esm/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
  111. package/dist/esm/adapter/resources/webgpu-external-texture.js +23 -0
  112. package/dist/esm/adapter/resources/webgpu-external-texture.js.map +1 -0
  113. package/dist/esm/adapter/resources/webgpu-framebuffer.js +93 -0
  114. package/dist/esm/adapter/resources/webgpu-framebuffer.js.map +1 -0
  115. package/dist/esm/adapter/resources/webgpu-query.js +2 -0
  116. package/dist/esm/adapter/resources/webgpu-query.js.map +1 -0
  117. package/dist/esm/adapter/resources/webgpu-render-pass.js +79 -0
  118. package/dist/esm/adapter/resources/webgpu-render-pass.js.map +1 -0
  119. package/dist/esm/adapter/resources/webgpu-render-pipeline.js +130 -0
  120. package/dist/esm/adapter/resources/webgpu-render-pipeline.js.map +1 -0
  121. package/dist/esm/adapter/resources/webgpu-sampler.js +20 -0
  122. package/dist/esm/adapter/resources/webgpu-sampler.js.map +1 -0
  123. package/dist/esm/adapter/resources/webgpu-shader.js +50 -0
  124. package/dist/esm/adapter/resources/webgpu-shader.js.map +1 -0
  125. package/dist/esm/adapter/resources/webgpu-texture.js +95 -0
  126. package/dist/esm/adapter/resources/webgpu-texture.js.map +1 -0
  127. package/dist/esm/adapter/webgpu-canvas-context.js +74 -0
  128. package/dist/esm/adapter/webgpu-canvas-context.js.map +1 -0
  129. package/dist/esm/adapter/webgpu-device.js +196 -0
  130. package/dist/esm/adapter/webgpu-device.js.map +1 -0
  131. package/dist/esm/adapter/webgpu-types.js +2 -0
  132. package/dist/esm/adapter/webgpu-types.js.map +1 -0
  133. package/dist/esm/bundle.js +4 -0
  134. package/dist/esm/bundle.js.map +1 -0
  135. package/dist/esm/glsl/glsllang.js +9 -0
  136. package/dist/esm/glsl/glsllang.js.map +1 -0
  137. package/dist/esm/index.js +8 -0
  138. package/dist/esm/index.js.map +1 -0
  139. package/dist/esm/init.js +4 -0
  140. package/dist/esm/init.js.map +1 -0
  141. package/dist/glsl/glsllang.js +9 -7
  142. package/dist/index.js +8 -6
  143. package/dist/init.js +1 -2
  144. package/package.json +8 -8
  145. package/src/adapter/helpers/webgpu-parameters.ts +7 -2
  146. package/src/adapter/resources/webgpu-command-encoder.ts +2 -1
  147. package/src/adapter/resources/webgpu-compute-pass.ts +4 -4
  148. package/src/adapter/resources/webgpu-compute-pipeline.ts +2 -1
  149. package/src/adapter/resources/webgpu-framebuffer.ts +3 -2
  150. package/src/adapter/resources/webgpu-render-pass.ts +2 -2
  151. package/src/adapter/resources/webgpu-render-pipeline.ts +2 -1
  152. package/src/adapter/resources/webgpu-shader.ts +1 -1
  153. package/src/adapter/webgpu-canvas-context.ts +3 -2
  154. package/src/adapter/webgpu-device.ts +2 -2
  155. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  156. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  157. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  158. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  159. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  160. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  161. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  162. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  163. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  164. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  165. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  166. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  167. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  168. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  169. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  170. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  171. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  172. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  173. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  174. package/dist/adapter/webgpu-device.js.map +0 -1
  175. package/dist/adapter/webgpu-types.js.map +0 -1
  176. package/dist/bundle.js.map +0 -1
  177. package/dist/glsl/glsllang.js.map +0 -1
  178. package/dist/index.js.map +0 -1
  179. package/dist/init.js.map +0 -1
@@ -1,2 +1,101 @@
1
+ /*
2
+ import {assert} from '@luma.gl/api';
3
+ import GL from '@luma.gl/constants';
1
4
 
2
- //# sourceMappingURL=accessor-to-format.js.map
5
+ type Accessor = Record<string, any>;
6
+
7
+ const FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {
8
+ uchar2: {type: 'uchar', size: 2},
9
+ uchar4: {type: 'uchar', size: 4},
10
+ char2: {type: 'char', size: 2},
11
+ char4: {type: 'char', size: 4},
12
+ uchar2norm: {type: 'uchar', size: 2, normalized: true},
13
+ uchar4norm: {type: 'uchar', size: 4, normalized: true},
14
+ char2norm: {type: 'char', size: 2, normalized: true},
15
+ char4norm: {type: 'char', size: 4, normalized: true},
16
+ ushort2: {type: 'ushort', size: 2},
17
+ ushort4: {type: 'ushort', size: 4},
18
+ short2: {type: 'short', size: 2},
19
+ short4: {type: 'short', size: 4},
20
+ ushort2norm: {type: 'ushort', size: 2, normalized: true},
21
+ ushort4norm: {type: 'ushort', size: 4, normalized: true},
22
+ short2norm: {type: 'short', size: 1, normalized: true},
23
+ short4norm: {type: 'short', size: 1, normalized: true},
24
+ half2: {type: 'half', size: 2},
25
+ half4: {type: 'half', size: 4},
26
+ float: {type: 'float', size: 1},
27
+ float2: {type: 'float', size: 2},
28
+ float3: {type: 'float', size: 3},
29
+ float4: {type: 'float', size: 4},
30
+ uint: {type: 'uint', size: 1, integer: true},
31
+ uint2: {type: 'uint', size: 2, integer: true},
32
+ uint3: {type: 'uint', size: 3, integer: true},
33
+ uint4: {type: 'uint', size: 4, integer: true},
34
+ int: {type: 'int', size: 1, integer: true},
35
+ int2: {type: 'int', size: 2, integer: true},
36
+ int3: {type: 'int', size: 3, integer: true},
37
+ int4: {type: 'int', size: 4, integer: true}
38
+ };
39
+
40
+ /**
41
+ * Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}
42
+ * @param {*} format
43
+ *
44
+ export function mapWebGPUFormatToAccessor(format) {
45
+ const accessorDefinition = FORMAT_TO_ACCESSOR[format];
46
+ assert(accessorDefinition, 'invalid attribute format');
47
+ return Object.freeze(accessorDefinition);
48
+ }
49
+
50
+ /**
51
+ * Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings
52
+ * @param {*} format
53
+ *
54
+ export function mapAccessorToWebGPUFormat(accessor) {
55
+ const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;
56
+ assert(size >=1 && size <=4);
57
+ // `norm` suffix (uchar4norm)
58
+ const norm = normalized ? 'norm' : '';
59
+ // size 1 is ommitted in format names (float vs float2)
60
+ const count = size === 1 ? '' : size;
61
+ switch (type) {
62
+ case GL.UNSIGNED_BYTE:
63
+ switch (size) {
64
+ case 2:
65
+ case 4:
66
+ return `uchar${count}${norm}`;
67
+ }
68
+ case GL.BYTE:
69
+ switch (size) {
70
+ case 2:
71
+ case 4:
72
+ return `char${count}${norm}`;
73
+ }
74
+ case GL.UNSIGNED_SHORT:
75
+ switch (size) {
76
+ case 2:
77
+ case 4:
78
+ return `ushort${count}${norm}`;
79
+ }
80
+ case GL.SHORT:
81
+ switch (size) {
82
+ case 2:
83
+ case 4:
84
+ return `short${count}${norm}`;
85
+ }
86
+ case GL.HALF_FLOAT:
87
+ switch (size) {
88
+ case 2:
89
+ case 4:
90
+ return `half${count}`;
91
+ }
92
+ case GL.FLOAT:
93
+ return `float${count}`;
94
+ case GL.UNSIGNED_INT:
95
+ return `uint${count}`;
96
+ case GL.INT:
97
+ return `int${count}`;
98
+ }
99
+ throw new Error('illegal accessor');
100
+ }
101
+ */
@@ -1,8 +1,7 @@
1
+ /** Ensure a texture format is WebGPU compatible */
1
2
  export function getWebGPUTextureFormat(format) {
2
- if (format.includes('webgl')) {
3
- throw new Error('webgl-only format');
4
- }
5
-
6
- return format;
3
+ if (format.includes('webgl')) {
4
+ throw new Error('webgl-only format');
5
+ }
6
+ return format;
7
7
  }
8
- //# sourceMappingURL=convert-texture-format.js.map
@@ -1,95 +1,91 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- const VS_GEN_MIPMAP = "#version 450\nconst vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));\nlayout(location = 0) out vec2 vTex;\nvoid main() {\n gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n vTex = gl_Position / 2.0f + vec2(0.5f);\n}";
3
- const FS_GEN_MIPMAP = "#version 450\nlayout(set = 0, binding = 0) uniform sampler imgSampler;\nlayout(set = 0, binding = 1) uniform texture2D img;\nlayout(location = 0) in vec2 vTex;\nlayout(location = 0) out vec4 outColor;\nvoid main() {\n outColor = texture(sampler2D(img, imgSampler), vTex);\n}";
1
+ // luma.gl, MIT license
2
+ // Forked from Kangz/mipmapper.js under MIT license Copyright 2020 Brandon Jones
3
+ // https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83
4
+ // @ts-nocheck this is written against outdated WebGPU API, needs an update pass
5
+ const VS_GEN_MIPMAP = `\#version 450
6
+ const vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));
7
+ layout(location = 0) out vec2 vTex;
8
+ void main() {
9
+ gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
10
+ vTex = gl_Position / 2.0f + vec2(0.5f);
11
+ }`;
12
+ const FS_GEN_MIPMAP = `#version 450
13
+ layout(set = 0, binding = 0) uniform sampler imgSampler;
14
+ layout(set = 0, binding = 1) uniform texture2D img;
15
+ layout(location = 0) in vec2 vTex;
16
+ layout(location = 0) out vec4 outColor;
17
+ void main() {
18
+ outColor = texture(sampler2D(img, imgSampler), vTex);
19
+ }`;
20
+ /** WebGPU does not have built-in mipmap creation */
4
21
  export class WebGPUMipmapGenerator {
5
- constructor(device, glslang) {
6
- _defineProperty(this, "device", void 0);
7
-
8
- _defineProperty(this, "mipmapSampler", void 0);
9
-
10
- _defineProperty(this, "mipmapPipeline", void 0);
11
-
12
- this.device = device;
13
- this.mipmapSampler = device.createSampler({
14
- minFilter: 'linear'
15
- });
16
- this.mipmapPipeline = device.createRenderPipeline({
17
- vertexStage: {
18
- module: device.createShaderModule({
19
- code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')
20
- }),
21
- entryPoint: 'main'
22
- },
23
- fragmentStage: {
24
- module: device.createShaderModule({
25
- code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')
26
- }),
27
- entryPoint: 'main'
28
- },
29
- primitiveTopology: 'triangle-strip',
30
- colorStates: [{
31
- format: 'rgba8unorm'
32
- }]
33
- });
34
- }
35
-
36
- generateMipmappedTexture(imageBitmap) {
37
- let textureSize = {
38
- width: imageBitmap.width,
39
- height: imageBitmap.height,
40
- depth: 1
41
- };
42
- const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
43
- const texture = this.device.createTexture({
44
- size: textureSize,
45
- format: 'rgba8unorm',
46
- usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
47
- mipLevelCount
48
- });
49
- this.device.queue.copyImageBitmapToTexture({
50
- imageBitmap
51
- }, {
52
- texture: srcTexture
53
- }, textureSize);
54
- const commandEncoder = this.device.createCommandEncoder({});
55
-
56
- for (let i = 1; i < mipLevelCount; ++i) {
57
- const passEncoder = commandEncoder.beginRenderPass({
58
- colorAttachments: [{
59
- attachment: texture.createView({
60
- baseMipLevel: i,
61
- mipLevelCount: 1
62
- }),
63
- loadValue: {
64
- r: 1.0,
65
- g: 0.0,
66
- b: 0.0,
67
- a: 0.0
68
- }
69
- }]
70
- });
71
- const bindGroup = this.device.createBindGroup({
72
- layout: this.mipmapPipeline.getBindGroupLayout(0),
73
- bindings: [{
74
- binding: 0,
75
- resource: this.mipmapSampler
76
- }, {
77
- binding: 1,
78
- resource: texture.createView({
79
- baseMipLevel: i - 1,
80
- mipLevelCount: 1
81
- })
82
- }]
83
- });
84
- passEncoder.setPipeline(this.mipmapPipeline);
85
- passEncoder.setBindGroup(0, bindGroup);
86
- passEncoder.draw(4);
87
- passEncoder.endPass();
22
+ constructor(device, glslang) {
23
+ this.device = device;
24
+ this.mipmapSampler = device.createSampler({ minFilter: 'linear' });
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
+ let 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
+ // Populate the top level of the srcTexture with the imageBitmap.
52
+ const texture = this.device.createTexture({
53
+ size: textureSize,
54
+ format: 'rgba8unorm',
55
+ usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
56
+ mipLevelCount
57
+ });
58
+ this.device.queue.copyImageBitmapToTexture({ imageBitmap }, { texture: srcTexture }, textureSize);
59
+ const commandEncoder = this.device.createCommandEncoder({});
60
+ for (let i = 1; i < mipLevelCount; ++i) {
61
+ const passEncoder = commandEncoder.beginRenderPass({
62
+ colorAttachments: [{
63
+ attachment: texture.createView({
64
+ baseMipLevel: i,
65
+ mipLevelCount: 1
66
+ }),
67
+ loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 },
68
+ }],
69
+ });
70
+ const bindGroup = this.device.createBindGroup({
71
+ layout: this.mipmapPipeline.getBindGroupLayout(0),
72
+ bindings: [{
73
+ binding: 0,
74
+ resource: this.mipmapSampler,
75
+ }, {
76
+ binding: 1,
77
+ resource: texture.createView({
78
+ baseMipLevel: i - 1,
79
+ mipLevelCount: 1
80
+ }),
81
+ }],
82
+ });
83
+ passEncoder.setPipeline(this.mipmapPipeline);
84
+ passEncoder.setBindGroup(0, bindGroup);
85
+ passEncoder.draw(4);
86
+ passEncoder.endPass();
87
+ }
88
+ this.device.queue.submit([commandEncoder.finish()]);
89
+ return texture;
88
90
  }
89
-
90
- this.device.queue.submit([commandEncoder.finish()]);
91
- return texture;
92
- }
93
-
94
91
  }
95
- //# sourceMappingURL=generate-mipmaps.js.map
@@ -1,60 +1,66 @@
1
1
  import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/api';
2
+ /**
3
+ * Create a WebGPU "bind group layout" from an array of luma.gl bindings
4
+ * @note bind groups can be automatically generated by WebGPU.
5
+ */
2
6
  export function makeBindGroupLayout(device, layout, bindings) {
3
- throw new Error('not implemented');
7
+ throw new Error('not implemented');
8
+ // return device.createBindGroupLayout({
9
+ // layout,
10
+ // entries: getBindGroupEntries(bindings)
11
+ // })
4
12
  }
13
+ /**
14
+ * Create a WebGPU "bind group" from an array of luma.gl bindings
15
+ */
5
16
  export function getBindGroup(device, bindGroupLayout, layout, bindings) {
6
- const entries = getBindGroupEntries(bindings, layout);
7
- return device.createBindGroup({
8
- layout: bindGroupLayout,
9
- entries
10
- });
17
+ const entries = getBindGroupEntries(bindings, layout);
18
+ return device.createBindGroup({
19
+ layout: bindGroupLayout,
20
+ entries
21
+ });
11
22
  }
12
23
  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;
24
+ const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
25
+ if (!bindingLayout) {
26
+ log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
27
+ }
28
+ return bindingLayout;
20
29
  }
21
-
30
+ /**
31
+ * @param bindings
32
+ * @returns
33
+ */
22
34
  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));
35
+ const entries = [];
36
+ for (const [bindingName, value] of Object.entries(bindings)) {
37
+ const bindingLayout = getShaderLayoutBinding(layout, bindingName);
38
+ if (bindingLayout) {
39
+ entries.push(getBindGroupEntry(value, bindingLayout.location));
40
+ }
30
41
  }
31
- }
32
-
33
- return entries;
42
+ return entries;
34
43
  }
35
-
36
44
  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');
45
+ if (binding instanceof Buffer) {
46
+ return {
47
+ binding: index,
48
+ resource: {
49
+ buffer: cast(binding).handle
50
+ }
51
+ };
52
+ }
53
+ if (binding instanceof Sampler) {
54
+ return {
55
+ binding: index,
56
+ resource: cast(binding).handle
57
+ };
58
+ }
59
+ else if (binding instanceof Texture) {
60
+ return {
61
+ binding: index,
62
+ resource: cast(binding).handle.createView()
63
+ };
64
+ }
65
+ throw new Error('invalid binding');
59
66
  }
60
- //# sourceMappingURL=get-bind-group.js.map
@@ -1,96 +1,109 @@
1
1
  import { decodeVertexFormat } from '@luma.gl/api';
2
+ /**
3
+ * Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.
4
+ * Converts luma.gl attribute definitions to a WebGPU GPUVertexBufferLayout[] array
5
+ * @param layout
6
+ * @param bufferMap The buffer map is optional
7
+ * @returns WebGPU layout intended for a GPURenderPassDescriptor.
8
+ */
2
9
  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
- for (const interleaved of mapping.attributes) {
14
- const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
15
- stepMode = attributeLayout.stepMode || 'vertex';
16
- vertexAttributes.push({
17
- format: attributeLayout.format,
18
- offset: byteOffset + byteStride,
19
- shaderLocation: attributeLayout.location
10
+ const vertexBufferLayouts = [];
11
+ const usedAttributes = new Set();
12
+ // First handle any buffers mentioned in `bufferMapping`
13
+ for (const mapping of bufferMap) {
14
+ // Build vertex attributes for one buffer
15
+ const vertexAttributes = [];
16
+ // TODO verify that all stepModes for one buffer are the same
17
+ let stepMode = 'vertex';
18
+ let byteStride = 0;
19
+ let byteOffset = mapping.byteOffset || 0;
20
+ // interleaved mapping {..., attributes: [{...}, ...]}
21
+ if ('attributes' in mapping) {
22
+ // const arrayStride = mapping.byteStride; TODO
23
+ for (const interleaved of mapping.attributes) {
24
+ const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
25
+ stepMode = attributeLayout.stepMode || 'vertex';
26
+ vertexAttributes.push({
27
+ format: attributeLayout.format,
28
+ offset: byteOffset + byteStride,
29
+ shaderLocation: attributeLayout.location
30
+ });
31
+ byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
32
+ }
33
+ // non-interleaved mapping (just set offset and stride)
34
+ }
35
+ else {
36
+ const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
37
+ byteStride = decodeVertexFormat(attributeLayout.format).byteLength,
38
+ stepMode = attributeLayout.stepMode || 'vertex';
39
+ vertexAttributes.push({
40
+ format: attributeLayout.format,
41
+ offset: byteOffset,
42
+ shaderLocation: attributeLayout.location
43
+ });
44
+ }
45
+ // Store all the attribute bindings for one buffer
46
+ vertexBufferLayouts.push({
47
+ arrayStride: mapping.byteStride || byteStride,
48
+ stepMode: stepMode || 'vertex',
49
+ attributes: vertexAttributes
20
50
  });
21
- byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
22
- }
23
- } else {
24
- const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
25
- byteStride = decodeVertexFormat(attributeLayout.format).byteLength, stepMode = attributeLayout.stepMode || 'vertex';
26
- vertexAttributes.push({
27
- format: attributeLayout.format,
28
- offset: byteOffset,
29
- shaderLocation: attributeLayout.location
30
- });
31
51
  }
32
-
33
- vertexBufferLayouts.push({
34
- arrayStride: mapping.byteStride || byteStride,
35
- stepMode: stepMode || 'vertex',
36
- attributes: vertexAttributes
37
- });
38
- }
39
-
40
- for (const attribute of layout.attributes) {
41
- if (!usedAttributes.has(attribute.name)) {
42
- vertexBufferLayouts.push({
43
- arrayStride: decodeVertexFormat(attribute.format).byteLength,
44
- stepMode: attribute.stepMode || 'vertex',
45
- attributes: [{
46
- format: attribute.format,
47
- offset: 0,
48
- shaderLocation: attribute.location
49
- }]
50
- });
52
+ // Add any non-mapped attributes
53
+ for (const attribute of layout.attributes) {
54
+ if (!usedAttributes.has(attribute.name)) {
55
+ vertexBufferLayouts.push({
56
+ arrayStride: decodeVertexFormat(attribute.format).byteLength,
57
+ stepMode: attribute.stepMode || 'vertex',
58
+ attributes: [{
59
+ format: attribute.format,
60
+ offset: 0,
61
+ shaderLocation: attribute.location
62
+ }]
63
+ });
64
+ }
51
65
  }
52
- }
53
-
54
- return vertexBufferLayouts;
66
+ return vertexBufferLayouts;
55
67
  }
56
68
  export function getBufferSlots(layout, bufferMap) {
57
- const usedAttributes = new Set();
58
- let bufferSlot = 0;
59
- const bufferSlots = {};
60
-
61
- for (const mapping of bufferMap) {
62
- if ('attributes' in mapping) {
63
- for (const interleaved of mapping.attributes) {
64
- usedAttributes.add(interleaved.name);
65
- }
66
- } else {
67
- usedAttributes.add(mapping.name);
69
+ const usedAttributes = new Set();
70
+ let bufferSlot = 0;
71
+ const bufferSlots = {};
72
+ // First handle any buffers mentioned in `bufferMapping`
73
+ for (const mapping of bufferMap) {
74
+ // interleaved mapping {..., attributes: [{...}, ...]}
75
+ if ('attributes' in mapping) {
76
+ for (const interleaved of mapping.attributes) {
77
+ usedAttributes.add(interleaved.name);
78
+ }
79
+ // non-interleaved mapping (just set offset and stride)
80
+ }
81
+ else {
82
+ usedAttributes.add(mapping.name);
83
+ }
84
+ bufferSlots[mapping.name] = bufferSlot++;
68
85
  }
69
-
70
- bufferSlots[mapping.name] = bufferSlot++;
71
- }
72
-
73
- for (const attribute of layout.attributes) {
74
- if (!usedAttributes.has(attribute.name)) {
75
- bufferSlots[attribute.name] = bufferSlot++;
86
+ // Add any non-mapped attributes
87
+ for (const attribute of layout.attributes) {
88
+ if (!usedAttributes.has(attribute.name)) {
89
+ bufferSlots[attribute.name] = bufferSlot++;
90
+ }
76
91
  }
77
- }
78
-
79
- return bufferSlots;
92
+ return bufferSlots;
80
93
  }
81
-
94
+ /**
95
+ * Looks up an attribute in the ShaderLayout.
96
+ * @throws if name is not in ShaderLayout
97
+ * @throws if name has already been referenced
98
+ */
82
99
  function findAttributeLayout(layout, name, attributeNames) {
83
- const attribute = layout.attributes.find(attribute => attribute.name === name);
84
-
85
- if (!attribute) {
86
- throw new Error("Unknown attribute ".concat(name));
87
- }
88
-
89
- if (attributeNames.has(name)) {
90
- throw new Error("Duplicate attribute ".concat(name));
91
- }
92
-
93
- attributeNames.add(name);
94
- return attribute;
100
+ const attribute = layout.attributes.find(attribute => attribute.name === name);
101
+ if (!attribute) {
102
+ throw new Error(`Unknown attribute ${name}`);
103
+ }
104
+ if (attributeNames.has(name)) {
105
+ throw new Error(`Duplicate attribute ${name}`);
106
+ }
107
+ attributeNames.add(name);
108
+ return attribute;
95
109
  }
96
- //# 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,cAAc,CAAC;AAYxC;;;GAGG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAsJ9D,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":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAexC;;;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"}