@luma.gl/webgpu 9.3.0-alpha.6 → 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.
- package/dist/adapter/helpers/get-bind-group.d.ts +3 -6
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +11 -14
- package/dist/adapter/helpers/get-bind-group.js.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +3 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +17 -12
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +1 -0
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +3 -13
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +68 -29
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +3 -3
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +17 -7
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +7 -9
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +26 -29
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-fence.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-fence.js +9 -1
- package/dist/adapter/resources/webgpu-fence.js.map +1 -1
- package/dist/adapter/resources/webgpu-pipeline-layout.d.ts +1 -1
- package/dist/adapter/resources/webgpu-pipeline-layout.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-pipeline-layout.js +10 -16
- package/dist/adapter/resources/webgpu-pipeline-layout.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -4
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +10 -10
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +10 -9
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +48 -38
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +17 -1
- package/dist/adapter/resources/webgpu-shader.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture.d.ts +8 -1
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +35 -43
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts +6 -2
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +60 -18
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/dist.dev.js +508 -311
- package/dist/dist.min.js +13 -13
- package/dist/index.cjs +439 -319
- package/dist/index.cjs.map +4 -4
- package/dist/wgsl/get-shader-layout-wgsl.d.ts.map +1 -1
- package/dist/wgsl/get-shader-layout-wgsl.js +8 -0
- package/dist/wgsl/get-shader-layout-wgsl.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter/helpers/get-bind-group.ts +18 -27
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +31 -12
- package/src/adapter/helpers/webgpu-parameters.ts +2 -0
- package/src/adapter/resources/webgpu-command-encoder.ts +99 -46
- package/src/adapter/resources/webgpu-compute-pass.ts +35 -8
- package/src/adapter/resources/webgpu-compute-pipeline.ts +43 -30
- package/src/adapter/resources/webgpu-fence.ts +11 -3
- package/src/adapter/resources/webgpu-pipeline-layout.ts +16 -14
- package/src/adapter/resources/webgpu-render-pass.ts +18 -14
- package/src/adapter/resources/webgpu-render-pipeline.ts +68 -46
- package/src/adapter/resources/webgpu-shader.ts +16 -1
- package/src/adapter/resources/webgpu-texture.ts +61 -44
- package/src/adapter/webgpu-device.ts +101 -25
- package/src/wgsl/get-shader-layout-wgsl.ts +9 -0
- package/dist/adapter/helpers/accessor-to-format.d.ts +0 -1
- package/dist/adapter/helpers/accessor-to-format.d.ts.map +0 -1
- package/dist/adapter/helpers/accessor-to-format.js +0 -105
- package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
- package/src/adapter/helpers/accessor-to-format.ts +0 -104
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
// / <reference types="@webgpu/types" />
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
|
+
Bindings,
|
|
10
|
+
ComputePipeline,
|
|
11
|
+
ComputeShaderLayout,
|
|
9
12
|
DeviceInfo,
|
|
10
13
|
DeviceLimits,
|
|
11
14
|
DeviceFeature,
|
|
@@ -31,6 +34,8 @@ import type {
|
|
|
31
34
|
DeviceProps,
|
|
32
35
|
CommandEncoderProps,
|
|
33
36
|
PipelineLayoutProps,
|
|
37
|
+
RenderPipeline,
|
|
38
|
+
ShaderLayout
|
|
34
39
|
} from '@luma.gl/core';
|
|
35
40
|
import {Device, DeviceFeatures} from '@luma.gl/core';
|
|
36
41
|
import {WebGPUBuffer} from './resources/webgpu-buffer';
|
|
@@ -53,6 +58,7 @@ import {WebGPUFence} from './resources/webgpu-fence';
|
|
|
53
58
|
|
|
54
59
|
import {getShaderLayoutFromWGSL} from '../wgsl/get-shader-layout-wgsl';
|
|
55
60
|
import {generateMipmapsWebGPU} from './helpers/generate-mipmaps-webgpu';
|
|
61
|
+
import {getBindGroup} from './helpers/get-bind-group';
|
|
56
62
|
import {
|
|
57
63
|
getCpuHotspotProfiler as getWebGPUCpuHotspotProfiler,
|
|
58
64
|
getCpuHotspotSubmitReason as getWebGPUCpuHotspotSubmitReason,
|
|
@@ -240,26 +246,35 @@ export class WebGPUDevice extends Device {
|
|
|
240
246
|
generateMipmapsWebGPU(this, texture);
|
|
241
247
|
}
|
|
242
248
|
|
|
249
|
+
override _createBindGroupLayoutWebGPU(
|
|
250
|
+
pipeline: RenderPipeline | ComputePipeline,
|
|
251
|
+
group: number
|
|
252
|
+
): GPUBindGroupLayout {
|
|
253
|
+
return (pipeline as WebGPURenderPipeline | WebGPUComputePipeline).handle.getBindGroupLayout(
|
|
254
|
+
group
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
override _createBindGroupWebGPU(
|
|
259
|
+
bindGroupLayout: unknown,
|
|
260
|
+
shaderLayout: ShaderLayout | ComputeShaderLayout,
|
|
261
|
+
bindings: Bindings,
|
|
262
|
+
group: number
|
|
263
|
+
): GPUBindGroup | null {
|
|
264
|
+
if (Object.keys(bindings).length === 0) {
|
|
265
|
+
return this.handle.createBindGroup({
|
|
266
|
+
layout: bindGroupLayout as GPUBindGroupLayout,
|
|
267
|
+
entries: []
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return getBindGroup(this, bindGroupLayout as GPUBindGroupLayout, shaderLayout, bindings, group);
|
|
272
|
+
}
|
|
273
|
+
|
|
243
274
|
submit(commandBuffer?: WebGPUCommandBuffer): void {
|
|
244
275
|
let submittedCommandEncoder: WebGPUCommandEncoder | null = null;
|
|
245
276
|
if (!commandBuffer) {
|
|
246
|
-
submittedCommandEncoder = this.
|
|
247
|
-
if (
|
|
248
|
-
submittedCommandEncoder.getTimeProfilingSlotCount() > 0 &&
|
|
249
|
-
submittedCommandEncoder.getTimeProfilingQuerySet() instanceof WebGPUQuerySet
|
|
250
|
-
) {
|
|
251
|
-
const querySet = submittedCommandEncoder.getTimeProfilingQuerySet() as WebGPUQuerySet;
|
|
252
|
-
querySet._encodeResolveToReadBuffer(submittedCommandEncoder, {
|
|
253
|
-
firstQuery: 0,
|
|
254
|
-
queryCount: submittedCommandEncoder.getTimeProfilingSlotCount()
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
commandBuffer = submittedCommandEncoder.finish();
|
|
258
|
-
this.commandEncoder.destroy();
|
|
259
|
-
this.commandEncoder = this.createCommandEncoder({
|
|
260
|
-
id: submittedCommandEncoder.props.id,
|
|
261
|
-
timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
|
|
262
|
-
});
|
|
277
|
+
({submittedCommandEncoder, commandBuffer} = this._finalizeDefaultCommandEncoderForSubmit());
|
|
263
278
|
}
|
|
264
279
|
|
|
265
280
|
const profiler = getWebGPUCpuHotspotProfiler(this);
|
|
@@ -318,6 +333,32 @@ export class WebGPUDevice extends Device {
|
|
|
318
333
|
}
|
|
319
334
|
}
|
|
320
335
|
|
|
336
|
+
private _finalizeDefaultCommandEncoderForSubmit(): {
|
|
337
|
+
submittedCommandEncoder: WebGPUCommandEncoder;
|
|
338
|
+
commandBuffer: WebGPUCommandBuffer;
|
|
339
|
+
} {
|
|
340
|
+
const submittedCommandEncoder = this.commandEncoder;
|
|
341
|
+
if (
|
|
342
|
+
submittedCommandEncoder.getTimeProfilingSlotCount() > 0 &&
|
|
343
|
+
submittedCommandEncoder.getTimeProfilingQuerySet() instanceof WebGPUQuerySet
|
|
344
|
+
) {
|
|
345
|
+
const querySet = submittedCommandEncoder.getTimeProfilingQuerySet() as WebGPUQuerySet;
|
|
346
|
+
querySet._encodeResolveToReadBuffer(submittedCommandEncoder, {
|
|
347
|
+
firstQuery: 0,
|
|
348
|
+
queryCount: submittedCommandEncoder.getTimeProfilingSlotCount()
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const commandBuffer = submittedCommandEncoder.finish();
|
|
353
|
+
this.commandEncoder.destroy();
|
|
354
|
+
this.commandEncoder = this.createCommandEncoder({
|
|
355
|
+
id: submittedCommandEncoder.props.id,
|
|
356
|
+
timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return {submittedCommandEncoder, commandBuffer};
|
|
360
|
+
}
|
|
361
|
+
|
|
321
362
|
// WebGPU specific
|
|
322
363
|
|
|
323
364
|
pushErrorScope(scope: 'validation' | 'out-of-memory'): void {
|
|
@@ -339,11 +380,22 @@ export class WebGPUDevice extends Device {
|
|
|
339
380
|
}
|
|
340
381
|
const profiler = getWebGPUCpuHotspotProfiler(this);
|
|
341
382
|
const startTime = profiler ? getTimestamp() : 0;
|
|
342
|
-
this.handle
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
383
|
+
this.handle
|
|
384
|
+
.popErrorScope()
|
|
385
|
+
.then((error: GPUError | null) => {
|
|
386
|
+
if (error) {
|
|
387
|
+
handler(error);
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
.catch((error: unknown) => {
|
|
391
|
+
if (this.shouldIgnoreDroppedInstanceError(error, 'popErrorScope')) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
396
|
+
this.reportError(new Error(`${this} popErrorScope failed: ${errorMessage}`), this)();
|
|
397
|
+
this.debug();
|
|
398
|
+
});
|
|
347
399
|
if (profiler) {
|
|
348
400
|
profiler.errorScopePopCount = (profiler.errorScopePopCount || 0) + 1;
|
|
349
401
|
profiler.errorScopeTimeMs = (profiler.errorScopeTimeMs || 0) + (getTimestamp() - startTime);
|
|
@@ -359,11 +411,22 @@ export class WebGPUDevice extends Device {
|
|
|
359
411
|
const vendor = this.adapterInfo.vendor || this.adapter.__brand || 'unknown';
|
|
360
412
|
const renderer = driver || '';
|
|
361
413
|
const version = driverVersion || '';
|
|
362
|
-
|
|
363
|
-
|
|
414
|
+
const fallback = Boolean(
|
|
415
|
+
(this.adapterInfo as any).isFallbackAdapter ??
|
|
416
|
+
(this.adapter as any).isFallbackAdapter ??
|
|
417
|
+
false
|
|
418
|
+
);
|
|
419
|
+
const softwareRenderer = /SwiftShader/i.test(
|
|
420
|
+
`${vendor} ${renderer} ${this.adapterInfo.architecture || ''}`
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const gpu =
|
|
424
|
+
vendor === 'apple' ? 'apple' : softwareRenderer || fallback ? 'software' : 'unknown'; // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',
|
|
364
425
|
const gpuArchitecture = this.adapterInfo.architecture || 'unknown';
|
|
365
426
|
const gpuBackend = (this.adapterInfo as any).backend || 'unknown';
|
|
366
|
-
const gpuType =
|
|
427
|
+
const gpuType =
|
|
428
|
+
((this.adapterInfo as any).type || '').split(' ')[0].toLowerCase() ||
|
|
429
|
+
(softwareRenderer || fallback ? 'cpu' : 'unknown');
|
|
367
430
|
|
|
368
431
|
return {
|
|
369
432
|
type: 'webgpu',
|
|
@@ -374,11 +437,24 @@ export class WebGPUDevice extends Device {
|
|
|
374
437
|
gpuType,
|
|
375
438
|
gpuBackend,
|
|
376
439
|
gpuArchitecture,
|
|
440
|
+
fallback,
|
|
377
441
|
shadingLanguage: 'wgsl',
|
|
378
442
|
shadingLanguageVersion: 100
|
|
379
443
|
};
|
|
380
444
|
}
|
|
381
445
|
|
|
446
|
+
shouldIgnoreDroppedInstanceError(error: unknown, operation?: string): boolean {
|
|
447
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
448
|
+
return (
|
|
449
|
+
errorMessage.includes('Instance dropped') &&
|
|
450
|
+
(!operation || errorMessage.includes(operation)) &&
|
|
451
|
+
(this._isLost ||
|
|
452
|
+
this.info.gpu === 'software' ||
|
|
453
|
+
this.info.gpuType === 'cpu' ||
|
|
454
|
+
Boolean(this.info.fallback))
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
382
458
|
protected _getFeatures(): DeviceFeatures {
|
|
383
459
|
// Initialize with actual WebGPU Features (note that unknown features may not be in DeviceFeature type)
|
|
384
460
|
const features = new Set<DeviceFeature>(this.handle.features as Set<DeviceFeature>);
|
|
@@ -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
|
-
*/
|