@luma.gl/webgpu 9.3.0-alpha.4 → 9.3.0-alpha.8

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 (125) hide show
  1. package/dist/adapter/helpers/cpu-hotspot-profiler.d.ts +54 -0
  2. package/dist/adapter/helpers/cpu-hotspot-profiler.d.ts.map +1 -0
  3. package/dist/adapter/helpers/cpu-hotspot-profiler.js +26 -0
  4. package/dist/adapter/helpers/cpu-hotspot-profiler.js.map +1 -0
  5. package/dist/adapter/helpers/generate-mipmaps-webgpu.d.ts +7 -0
  6. package/dist/adapter/helpers/generate-mipmaps-webgpu.d.ts.map +1 -0
  7. package/dist/adapter/helpers/generate-mipmaps-webgpu.js +490 -0
  8. package/dist/adapter/helpers/generate-mipmaps-webgpu.js.map +1 -0
  9. package/dist/adapter/helpers/get-bind-group.d.ts +4 -6
  10. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-bind-group.js +31 -30
  12. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  13. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +3 -1
  14. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  15. package/dist/adapter/helpers/get-vertex-buffer-layout.js +17 -12
  16. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  17. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  18. package/dist/adapter/helpers/webgpu-parameters.js +1 -0
  19. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  20. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  21. package/dist/adapter/resources/webgpu-buffer.js +19 -3
  22. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  23. package/dist/adapter/resources/webgpu-command-buffer.js +1 -1
  24. package/dist/adapter/resources/webgpu-command-buffer.js.map +1 -1
  25. package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -16
  26. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgpu-command-encoder.js +89 -32
  28. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  29. package/dist/adapter/resources/webgpu-compute-pass.d.ts +3 -3
  30. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  31. package/dist/adapter/resources/webgpu-compute-pass.js +30 -12
  32. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  33. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +7 -9
  34. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  35. package/dist/adapter/resources/webgpu-compute-pipeline.js +30 -17
  36. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  37. package/dist/adapter/resources/webgpu-fence.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-fence.js +9 -1
  39. package/dist/adapter/resources/webgpu-fence.js.map +1 -1
  40. package/dist/adapter/resources/webgpu-framebuffer.d.ts +6 -0
  41. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgpu-framebuffer.js +16 -0
  43. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  44. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts +1 -1
  45. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts.map +1 -1
  46. package/dist/adapter/resources/webgpu-pipeline-layout.js +10 -16
  47. package/dist/adapter/resources/webgpu-pipeline-layout.js.map +1 -1
  48. package/dist/adapter/resources/webgpu-query-set.d.ts +33 -4
  49. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -1
  50. package/dist/adapter/resources/webgpu-query-set.js +145 -4
  51. package/dist/adapter/resources/webgpu-query-set.js.map +1 -1
  52. package/dist/adapter/resources/webgpu-render-pass.d.ts +6 -3
  53. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  54. package/dist/adapter/resources/webgpu-render-pass.js +78 -34
  55. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  56. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +14 -10
  57. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  58. package/dist/adapter/resources/webgpu-render-pipeline.js +56 -35
  59. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  60. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgpu-sampler.js +4 -0
  62. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  63. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgpu-shader.js +17 -1
  65. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  66. package/dist/adapter/resources/webgpu-texture-view.d.ts +6 -0
  67. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
  68. package/dist/adapter/resources/webgpu-texture-view.js +47 -11
  69. package/dist/adapter/resources/webgpu-texture-view.js.map +1 -1
  70. package/dist/adapter/resources/webgpu-texture.d.ts +18 -5
  71. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgpu-texture.js +148 -97
  73. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  74. package/dist/adapter/resources/webgpu-vertex-array.js +1 -1
  75. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -1
  76. package/dist/adapter/webgpu-canvas-context.d.ts +2 -0
  77. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  78. package/dist/adapter/webgpu-canvas-context.js +78 -19
  79. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  80. package/dist/adapter/webgpu-device.d.ts +10 -2
  81. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  82. package/dist/adapter/webgpu-device.js +159 -13
  83. package/dist/adapter/webgpu-device.js.map +1 -1
  84. package/dist/adapter/webgpu-presentation-context.d.ts +25 -0
  85. package/dist/adapter/webgpu-presentation-context.d.ts.map +1 -0
  86. package/dist/adapter/webgpu-presentation-context.js +144 -0
  87. package/dist/adapter/webgpu-presentation-context.js.map +1 -0
  88. package/dist/dist.dev.js +3180 -1849
  89. package/dist/dist.min.js +168 -9
  90. package/dist/index.cjs +1640 -405
  91. package/dist/index.cjs.map +4 -4
  92. package/dist/wgsl/get-shader-layout-wgsl.d.ts.map +1 -1
  93. package/dist/wgsl/get-shader-layout-wgsl.js +8 -0
  94. package/dist/wgsl/get-shader-layout-wgsl.js.map +1 -1
  95. package/package.json +5 -5
  96. package/src/adapter/helpers/cpu-hotspot-profiler.ts +70 -0
  97. package/src/adapter/helpers/generate-mipmaps-webgpu.ts +583 -0
  98. package/src/adapter/helpers/get-bind-group.ts +42 -49
  99. package/src/adapter/helpers/get-vertex-buffer-layout.ts +31 -12
  100. package/src/adapter/helpers/webgpu-parameters.ts +2 -0
  101. package/src/adapter/resources/webgpu-buffer.ts +18 -3
  102. package/src/adapter/resources/webgpu-command-buffer.ts +1 -1
  103. package/src/adapter/resources/webgpu-command-encoder.ts +129 -50
  104. package/src/adapter/resources/webgpu-compute-pass.ts +48 -13
  105. package/src/adapter/resources/webgpu-compute-pipeline.ts +49 -18
  106. package/src/adapter/resources/webgpu-fence.ts +11 -3
  107. package/src/adapter/resources/webgpu-framebuffer.ts +21 -0
  108. package/src/adapter/resources/webgpu-pipeline-layout.ts +16 -14
  109. package/src/adapter/resources/webgpu-query-set.ts +185 -9
  110. package/src/adapter/resources/webgpu-render-pass.ts +92 -40
  111. package/src/adapter/resources/webgpu-render-pipeline.ts +83 -44
  112. package/src/adapter/resources/webgpu-sampler.ts +5 -0
  113. package/src/adapter/resources/webgpu-shader.ts +16 -1
  114. package/src/adapter/resources/webgpu-texture-view.ts +51 -11
  115. package/src/adapter/resources/webgpu-texture.ts +198 -132
  116. package/src/adapter/resources/webgpu-vertex-array.ts +1 -1
  117. package/src/adapter/webgpu-canvas-context.ts +91 -26
  118. package/src/adapter/webgpu-device.ts +212 -17
  119. package/src/adapter/webgpu-presentation-context.ts +180 -0
  120. package/src/wgsl/get-shader-layout-wgsl.ts +9 -0
  121. package/dist/adapter/helpers/accessor-to-format.d.ts +0 -1
  122. package/dist/adapter/helpers/accessor-to-format.d.ts.map +0 -1
  123. package/dist/adapter/helpers/accessor-to-format.js +0 -105
  124. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  125. package/src/adapter/helpers/accessor-to-format.ts +0 -104
@@ -0,0 +1,180 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // prettier-ignore
6
+ // / <reference types="@webgpu/types" />
7
+
8
+ import type {PresentationContextProps, TextureFormatDepthStencil} from '@luma.gl/core';
9
+ import {PresentationContext, Texture, log} from '@luma.gl/core';
10
+ import type {WebGPUDevice} from './webgpu-device';
11
+ import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
12
+ import {WebGPUTexture} from './resources/webgpu-texture';
13
+ import {getCpuHotspotProfiler, getTimestamp} from './helpers/cpu-hotspot-profiler';
14
+
15
+ /**
16
+ * A WebGPU PresentationContext renders directly into its destination canvas.
17
+ */
18
+ export class WebGPUPresentationContext extends PresentationContext {
19
+ readonly device: WebGPUDevice;
20
+ readonly handle: GPUCanvasContext;
21
+
22
+ private colorAttachment: WebGPUTexture | null = null;
23
+ private depthStencilAttachment: WebGPUTexture | null = null;
24
+ private framebuffer: WebGPUFramebuffer | null = null;
25
+
26
+ get [Symbol.toStringTag](): string {
27
+ return 'WebGPUPresentationContext';
28
+ }
29
+
30
+ constructor(device: WebGPUDevice, props: PresentationContextProps = {}) {
31
+ super(props);
32
+ const contextLabel = `${this[Symbol.toStringTag]}(${this.id})`;
33
+
34
+ const context = this.canvas.getContext('webgpu');
35
+ if (!context) {
36
+ throw new Error(`${contextLabel}: Failed to create WebGPU presentation context`);
37
+ }
38
+ this.device = device;
39
+ this.handle = context;
40
+
41
+ this._setAutoCreatedCanvasId(`${this.device.id}-presentation-canvas`);
42
+ this._configureDevice();
43
+ this._startObservers();
44
+ }
45
+
46
+ override destroy(): void {
47
+ if (this.framebuffer) {
48
+ this.framebuffer.destroy();
49
+ this.framebuffer = null;
50
+ }
51
+ if (this.colorAttachment) {
52
+ this.colorAttachment.destroy();
53
+ this.colorAttachment = null;
54
+ }
55
+ if (this.depthStencilAttachment) {
56
+ this.depthStencilAttachment.destroy();
57
+ this.depthStencilAttachment = null;
58
+ }
59
+ this.handle.unconfigure();
60
+ super.destroy();
61
+ }
62
+
63
+ present(): void {
64
+ this.device.submit();
65
+ }
66
+
67
+ protected override _configureDevice(): void {
68
+ if (this.depthStencilAttachment) {
69
+ this.depthStencilAttachment.destroy();
70
+ this.depthStencilAttachment = null;
71
+ }
72
+
73
+ this.handle.configure({
74
+ device: this.device.handle,
75
+ format: this.device.preferredColorFormat,
76
+ colorSpace: this.props.colorSpace,
77
+ alphaMode: this.props.alphaMode
78
+ });
79
+
80
+ this._createDepthStencilAttachment(this.device.preferredDepthFormat);
81
+ }
82
+
83
+ protected override _getCurrentFramebuffer(
84
+ options: {depthStencilFormat?: TextureFormatDepthStencil | false} = {
85
+ depthStencilFormat: 'depth24plus'
86
+ }
87
+ ): WebGPUFramebuffer {
88
+ const profiler = getCpuHotspotProfiler(this.device);
89
+ const startTime = profiler ? getTimestamp() : 0;
90
+ if (profiler) {
91
+ profiler.framebufferAcquireCount = (profiler.framebufferAcquireCount || 0) + 1;
92
+ }
93
+
94
+ try {
95
+ const currentColorAttachment = this._getCurrentTexture();
96
+ if (
97
+ currentColorAttachment.width !== this.drawingBufferWidth ||
98
+ currentColorAttachment.height !== this.drawingBufferHeight
99
+ ) {
100
+ const [oldWidth, oldHeight] = this.getDrawingBufferSize();
101
+ this.drawingBufferWidth = currentColorAttachment.width;
102
+ this.drawingBufferHeight = currentColorAttachment.height;
103
+ log.log(
104
+ 1,
105
+ `${this[Symbol.toStringTag]}(${this.id}): Resized to compensate for initial canvas size mismatch ${oldWidth}x${oldHeight} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`
106
+ )();
107
+ }
108
+
109
+ if (options?.depthStencilFormat) {
110
+ this._createDepthStencilAttachment(options.depthStencilFormat);
111
+ }
112
+
113
+ this.framebuffer ||= new WebGPUFramebuffer(this.device, {
114
+ id: `${this.id}#framebuffer`,
115
+ colorAttachments: [currentColorAttachment],
116
+ depthStencilAttachment: null
117
+ });
118
+ this.framebuffer._reinitialize(
119
+ currentColorAttachment.view,
120
+ options?.depthStencilFormat ? this.depthStencilAttachment?.view || null : null
121
+ );
122
+ return this.framebuffer;
123
+ } finally {
124
+ if (profiler) {
125
+ profiler.framebufferAcquireTimeMs =
126
+ (profiler.framebufferAcquireTimeMs || 0) + (getTimestamp() - startTime);
127
+ }
128
+ }
129
+ }
130
+
131
+ private _getCurrentTexture(): WebGPUTexture {
132
+ const profiler = getCpuHotspotProfiler(this.device);
133
+ const currentTextureStartTime = profiler ? getTimestamp() : 0;
134
+ const handle = this.handle.getCurrentTexture();
135
+ if (profiler) {
136
+ profiler.currentTextureAcquireCount = (profiler.currentTextureAcquireCount || 0) + 1;
137
+ profiler.currentTextureAcquireTimeMs =
138
+ (profiler.currentTextureAcquireTimeMs || 0) + (getTimestamp() - currentTextureStartTime);
139
+ }
140
+ if (!this.colorAttachment) {
141
+ this.colorAttachment = this.device.createTexture({
142
+ id: `${this.id}#color-texture`,
143
+ handle,
144
+ format: this.device.preferredColorFormat,
145
+ width: handle.width,
146
+ height: handle.height
147
+ });
148
+ return this.colorAttachment;
149
+ }
150
+
151
+ this.colorAttachment._reinitialize(handle, {
152
+ handle,
153
+ format: this.device.preferredColorFormat,
154
+ width: handle.width,
155
+ height: handle.height
156
+ });
157
+ return this.colorAttachment;
158
+ }
159
+
160
+ private _createDepthStencilAttachment(
161
+ depthStencilFormat: TextureFormatDepthStencil
162
+ ): WebGPUTexture {
163
+ const needsNewDepthStencilAttachment =
164
+ !this.depthStencilAttachment ||
165
+ this.depthStencilAttachment.width !== this.drawingBufferWidth ||
166
+ this.depthStencilAttachment.height !== this.drawingBufferHeight ||
167
+ this.depthStencilAttachment.format !== depthStencilFormat;
168
+ if (needsNewDepthStencilAttachment) {
169
+ this.depthStencilAttachment?.destroy();
170
+ this.depthStencilAttachment = this.device.createTexture({
171
+ id: `${this.id}#depth-stencil-texture`,
172
+ usage: Texture.RENDER_ATTACHMENT,
173
+ format: depthStencilFormat,
174
+ width: this.drawingBufferWidth,
175
+ height: this.drawingBufferHeight
176
+ });
177
+ }
178
+ return this.depthStencilAttachment!;
179
+ }
180
+ }
@@ -41,6 +41,15 @@ export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
41
41
  });
42
42
  }
43
43
 
44
+ for (const storageBuffer of parsedWGSL.storage) {
45
+ shaderLayout.bindings.push({
46
+ type: storageBuffer.access === 'read' ? 'read-only-storage' : 'storage',
47
+ name: storageBuffer.name,
48
+ group: storageBuffer.group,
49
+ location: storageBuffer.binding
50
+ });
51
+ }
52
+
44
53
  for (const texture of parsedWGSL.textures) {
45
54
  const bindingDeclaration: TextureBindingLayout = {
46
55
  type: 'texture',
@@ -1 +0,0 @@
1
- //# sourceMappingURL=accessor-to-format.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accessor-to-format.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/accessor-to-format.ts"],"names":[],"mappings":""}
@@ -1,105 +0,0 @@
1
- "use strict";
2
- // luma.gl
3
- // SPDX-License-Identifier: MIT
4
- // Copyright (c) vis.gl contributors
5
- /*
6
- import {assert} from '@luma.gl/core';
7
-
8
- type Accessor = Record<string, any>;
9
-
10
- const FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {
11
- uchar2: {type: 'uchar', size: 2},
12
- uchar4: {type: 'uchar', size: 4},
13
- char2: {type: 'char', size: 2},
14
- char4: {type: 'char', size: 4},
15
- uchar2norm: {type: 'uchar', size: 2, normalized: true},
16
- uchar4norm: {type: 'uchar', size: 4, normalized: true},
17
- char2norm: {type: 'char', size: 2, normalized: true},
18
- char4norm: {type: 'char', size: 4, normalized: true},
19
- ushort2: {type: 'ushort', size: 2},
20
- ushort4: {type: 'ushort', size: 4},
21
- short2: {type: 'short', size: 2},
22
- short4: {type: 'short', size: 4},
23
- ushort2norm: {type: 'ushort', size: 2, normalized: true},
24
- ushort4norm: {type: 'ushort', size: 4, normalized: true},
25
- short2norm: {type: 'short', size: 1, normalized: true},
26
- short4norm: {type: 'short', size: 1, normalized: true},
27
- half2: {type: 'half', size: 2},
28
- half4: {type: 'half', size: 4},
29
- float: {type: 'float', size: 1},
30
- float2: {type: 'float', size: 2},
31
- float3: {type: 'float', size: 3},
32
- float4: {type: 'float', size: 4},
33
- uint: {type: 'uint', size: 1, integer: true},
34
- uint2: {type: 'uint', size: 2, integer: true},
35
- uint3: {type: 'uint', size: 3, integer: true},
36
- uint4: {type: 'uint', size: 4, integer: true},
37
- int: {type: 'int', size: 1, integer: true},
38
- int2: {type: 'int', size: 2, integer: true},
39
- int3: {type: 'int', size: 3, integer: true},
40
- int4: {type: 'int', size: 4, integer: true}
41
- };
42
-
43
- /**
44
- * Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}
45
- * @param {*} format
46
- *
47
- export function mapWebGPUFormatToAccessor(format) {
48
- const accessorDefinition = FORMAT_TO_ACCESSOR[format];
49
- assert(accessorDefinition, 'invalid attribute format');
50
- return Object.freeze(accessorDefinition);
51
- }
52
-
53
- /**
54
- * Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings
55
- * @param {*} format
56
- *
57
- export function mapAccessorToWebGPUFormat(accessor) {
58
- const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;
59
- assert(size >=1 && size <=4);
60
- // `norm` suffix (uchar4norm)
61
- const norm = normalized ? 'norm' : '';
62
- // size 1 is ommitted in format names (float vs float2)
63
- const count = size === 1 ? '' : size;
64
- switch (type) {
65
- case GL.UNSIGNED_BYTE:
66
- switch (size) {
67
- case 2:
68
- case 4:
69
- return `uchar${count}${norm}`;
70
- }
71
- case GL.BYTE:
72
- switch (size) {
73
- case 2:
74
- case 4:
75
- return `char${count}${norm}`;
76
- }
77
- case GL.UNSIGNED_SHORT:
78
- switch (size) {
79
- case 2:
80
- case 4:
81
- return `ushort${count}${norm}`;
82
- }
83
- case GL.SHORT:
84
- switch (size) {
85
- case 2:
86
- case 4:
87
- return `short${count}${norm}`;
88
- }
89
- case GL.HALF_FLOAT:
90
- switch (size) {
91
- case 2:
92
- case 4:
93
- return `half${count}`;
94
- }
95
- case GL.FLOAT:
96
- return `float${count}`;
97
- case GL.UNSIGNED_INT:
98
- return `uint${count}`;
99
- case GL.INT:
100
- return `int${count}`;
101
- }
102
- throw new Error('illegal accessor');
103
- }
104
- */
105
- //# sourceMappingURL=accessor-to-format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accessor-to-format.js","sourceRoot":"","sources":["../../../src/adapter/helpers/accessor-to-format.ts"],"names":[],"mappings":";AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmGE"}
@@ -1,104 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- /*
6
- import {assert} from '@luma.gl/core';
7
-
8
- type Accessor = Record<string, any>;
9
-
10
- const FORMAT_TO_ACCESSOR: Record<GPUVertexFormat, Accessor> = {
11
- uchar2: {type: 'uchar', size: 2},
12
- uchar4: {type: 'uchar', size: 4},
13
- char2: {type: 'char', size: 2},
14
- char4: {type: 'char', size: 4},
15
- uchar2norm: {type: 'uchar', size: 2, normalized: true},
16
- uchar4norm: {type: 'uchar', size: 4, normalized: true},
17
- char2norm: {type: 'char', size: 2, normalized: true},
18
- char4norm: {type: 'char', size: 4, normalized: true},
19
- ushort2: {type: 'ushort', size: 2},
20
- ushort4: {type: 'ushort', size: 4},
21
- short2: {type: 'short', size: 2},
22
- short4: {type: 'short', size: 4},
23
- ushort2norm: {type: 'ushort', size: 2, normalized: true},
24
- ushort4norm: {type: 'ushort', size: 4, normalized: true},
25
- short2norm: {type: 'short', size: 1, normalized: true},
26
- short4norm: {type: 'short', size: 1, normalized: true},
27
- half2: {type: 'half', size: 2},
28
- half4: {type: 'half', size: 4},
29
- float: {type: 'float', size: 1},
30
- float2: {type: 'float', size: 2},
31
- float3: {type: 'float', size: 3},
32
- float4: {type: 'float', size: 4},
33
- uint: {type: 'uint', size: 1, integer: true},
34
- uint2: {type: 'uint', size: 2, integer: true},
35
- uint3: {type: 'uint', size: 3, integer: true},
36
- uint4: {type: 'uint', size: 4, integer: true},
37
- int: {type: 'int', size: 1, integer: true},
38
- int2: {type: 'int', size: 2, integer: true},
39
- int3: {type: 'int', size: 3, integer: true},
40
- int4: {type: 'int', size: 4, integer: true}
41
- };
42
-
43
- /**
44
- * Convert from WebGPU attribute format strings to accessor {type, size, normalized, integer}
45
- * @param {*} format
46
- *
47
- export function mapWebGPUFormatToAccessor(format) {
48
- const accessorDefinition = FORMAT_TO_ACCESSOR[format];
49
- assert(accessorDefinition, 'invalid attribute format');
50
- return Object.freeze(accessorDefinition);
51
- }
52
-
53
- /**
54
- * Convert from accessor {type, size, normalized, integer} to WebGPU attribute format strings
55
- * @param {*} format
56
- *
57
- export function mapAccessorToWebGPUFormat(accessor) {
58
- const {type = GL.FLOAT, size = 1, normalized = false, integer = false} = accessor;
59
- assert(size >=1 && size <=4);
60
- // `norm` suffix (uchar4norm)
61
- const norm = normalized ? 'norm' : '';
62
- // size 1 is ommitted in format names (float vs float2)
63
- const count = size === 1 ? '' : size;
64
- switch (type) {
65
- case GL.UNSIGNED_BYTE:
66
- switch (size) {
67
- case 2:
68
- case 4:
69
- return `uchar${count}${norm}`;
70
- }
71
- case GL.BYTE:
72
- switch (size) {
73
- case 2:
74
- case 4:
75
- return `char${count}${norm}`;
76
- }
77
- case GL.UNSIGNED_SHORT:
78
- switch (size) {
79
- case 2:
80
- case 4:
81
- return `ushort${count}${norm}`;
82
- }
83
- case GL.SHORT:
84
- switch (size) {
85
- case 2:
86
- case 4:
87
- return `short${count}${norm}`;
88
- }
89
- case GL.HALF_FLOAT:
90
- switch (size) {
91
- case 2:
92
- case 4:
93
- return `half${count}`;
94
- }
95
- case GL.FLOAT:
96
- return `float${count}`;
97
- case GL.UNSIGNED_INT:
98
- return `uint${count}`;
99
- case GL.INT:
100
- return `int${count}`;
101
- }
102
- throw new Error('illegal accessor');
103
- }
104
- */