@wasi-gfx/js-webgpu 0.4.0 → 0.4.2
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/globals.js +3 -1
- package/dist/webgpu.d.ts +24 -3
- package/dist/webgpu.js +235 -126
- package/package.json +1 -1
package/dist/globals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getGpu, GPU, GPUAdapter, GPUDeviceLostInfo, GPUDevice, GPUQueue, GPUBuffer, GPUBufferUsage, GPUMapMode, GPUTextureUsage, GPUTexture, GPUTextureView, GPUSampler, GPUBindGroupLayout, GPUPipelineLayout, GPUBindGroup, GPUShaderModule, GPUShaderStage, GPUComputePipeline, GPURenderPipeline, GPUColorWrite, GPUCommandEncoder, GPURenderPassEncoder, GPUComputePassEncoder, GPUCommandBuffer, GPUQuerySet, GPUAdapterInfo, GPUSupportedLimits, GPUSupportedFeatures, GPURenderBundleEncoder, GPURenderBundle, GPUError, GPUValidationError, GPUOutOfMemoryError, GPUInternalError, GPUPipelineError } from "./webgpu";
|
|
1
|
+
import { getGpu, GPU, GPUAdapter, GPUDeviceLostInfo, GPUDevice, GPUQueue, GPUBuffer, GPUBufferUsage, GPUMapMode, GPUTextureUsage, GPUTexture, GPUTextureView, GPUExternalTexture, GPUSampler, GPUBindGroupLayout, GPUPipelineLayout, GPUBindGroup, GPUShaderModule, GPUShaderStage, GPUComputePipeline, GPURenderPipeline, GPUColorWrite, GPUCommandEncoder, GPURenderPassEncoder, GPUComputePassEncoder, GPUCommandBuffer, GPUQuerySet, GPUAdapterInfo, GPUSupportedLimits, GPUSupportedFeatures, GPURenderBundleEncoder, GPURenderBundle, GPUError, GPUValidationError, GPUOutOfMemoryError, GPUInternalError, GPUPipelineError, WGSLLanguageFeatures } from "./webgpu";
|
|
2
2
|
class Navigator {
|
|
3
3
|
gpu;
|
|
4
4
|
constructor() {
|
|
@@ -21,6 +21,7 @@ export function declareGlobals() {
|
|
|
21
21
|
defineGlobal("GPUAdapterInfo", GPUAdapterInfo);
|
|
22
22
|
defineGlobal("GPUSupportedLimits", GPUSupportedLimits);
|
|
23
23
|
defineGlobal("GPUSupportedFeatures", GPUSupportedFeatures);
|
|
24
|
+
defineGlobal("WGSLLanguageFeatures", WGSLLanguageFeatures);
|
|
24
25
|
defineGlobal("GPUDeviceLostInfo", GPUDeviceLostInfo);
|
|
25
26
|
defineGlobal("GPUDevice", GPUDevice);
|
|
26
27
|
defineGlobal("GPUQueue", GPUQueue);
|
|
@@ -30,6 +31,7 @@ export function declareGlobals() {
|
|
|
30
31
|
defineGlobal("GPUTextureUsage", GPUTextureUsage);
|
|
31
32
|
defineGlobal("GPUTexture", GPUTexture);
|
|
32
33
|
defineGlobal("GPUTextureView", GPUTextureView);
|
|
34
|
+
defineGlobal("GPUExternalTexture", GPUExternalTexture);
|
|
33
35
|
defineGlobal("GPUSampler", GPUSampler);
|
|
34
36
|
defineGlobal("GPUBindGroupLayout", GPUBindGroupLayout);
|
|
35
37
|
defineGlobal("GPUPipelineLayout", GPUPipelineLayout);
|
package/dist/webgpu.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { EventTarget, inner } from './common';
|
|
|
3
3
|
export declare function convertTextureUsageWebToWasi(usage: number): gfx.GpuTextureUsage;
|
|
4
4
|
export declare function convertTextureFormatWebToWasi(name: GPUTextureFormat): gfx.GpuTextureFormat;
|
|
5
5
|
export declare class GPU implements globalThis.GPU {
|
|
6
|
+
#private;
|
|
6
7
|
[inner]: gfx.Gpu;
|
|
7
8
|
constructor(k: symbol, i: gfx.Gpu);
|
|
8
9
|
get __brand(): 'GPU';
|
|
@@ -33,6 +34,18 @@ export declare class GPUSupportedFeatures implements globalThis.GPUSupportedFeat
|
|
|
33
34
|
values(): SetIterator<string>;
|
|
34
35
|
[Symbol.iterator](): SetIterator<string>;
|
|
35
36
|
}
|
|
37
|
+
export declare class WGSLLanguageFeatures implements globalThis.WGSLLanguageFeatures {
|
|
38
|
+
[inner]: gfx.WgslLanguageFeatures;
|
|
39
|
+
constructor(k: symbol, i: gfx.WgslLanguageFeatures);
|
|
40
|
+
get __brand(): 'WGSLLanguageFeatures';
|
|
41
|
+
get size(): number;
|
|
42
|
+
has(value: string): boolean;
|
|
43
|
+
forEach(callbackfn: (value: string, value2: string, set: ReadonlySet<string>) => void, thisArg?: any): void;
|
|
44
|
+
entries(): SetIterator<[string, string]>;
|
|
45
|
+
keys(): SetIterator<string>;
|
|
46
|
+
values(): SetIterator<string>;
|
|
47
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
48
|
+
}
|
|
36
49
|
export declare class GPUSupportedLimits implements globalThis.GPUSupportedLimits {
|
|
37
50
|
[inner]: gfx.GpuSupportedLimits;
|
|
38
51
|
constructor(k: symbol, i: gfx.GpuSupportedLimits);
|
|
@@ -152,7 +165,8 @@ export declare class GPURenderBundleEncoder implements globalThis.GPURenderBundl
|
|
|
152
165
|
pushDebugGroup(groupLabel: string): undefined;
|
|
153
166
|
popDebugGroup(): undefined;
|
|
154
167
|
insertDebugMarker(markerLabel: string): undefined;
|
|
155
|
-
setBindGroup(index:
|
|
168
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsets?: Iterable<GPUBufferDynamicOffset>): undefined;
|
|
169
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsetsData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): undefined;
|
|
156
170
|
setPipeline(pipeline: GPURenderPipeline): undefined;
|
|
157
171
|
setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
158
172
|
setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer | null | undefined, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
@@ -290,6 +304,11 @@ export declare class GPUTexture implements globalThis.GPUTexture {
|
|
|
290
304
|
createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView;
|
|
291
305
|
destroy(): undefined;
|
|
292
306
|
}
|
|
307
|
+
export declare class GPUExternalTexture implements globalThis.GPUExternalTexture {
|
|
308
|
+
constructor(k: symbol);
|
|
309
|
+
get __brand(): 'GPUExternalTexture';
|
|
310
|
+
label: string;
|
|
311
|
+
}
|
|
293
312
|
export declare class GPUCommandEncoder implements globalThis.GPUCommandEncoder {
|
|
294
313
|
[inner]: gfx.GpuCommandEncoder;
|
|
295
314
|
constructor(k: symbol, i: gfx.GpuCommandEncoder);
|
|
@@ -323,7 +342,8 @@ export declare class GPUComputePassEncoder implements globalThis.GPUComputePassE
|
|
|
323
342
|
pushDebugGroup(groupLabel: string): undefined;
|
|
324
343
|
popDebugGroup(): undefined;
|
|
325
344
|
insertDebugMarker(markerLabel: string): undefined;
|
|
326
|
-
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null,
|
|
345
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsets?: Iterable<GPUBufferDynamicOffset>): undefined;
|
|
346
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsetsData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): undefined;
|
|
327
347
|
setImmediates(rangeOffset: GPUSize32, data: GPUAllowSharedBufferSource, dataOffset?: GPUSize64, dataSize?: GPUSize64): undefined;
|
|
328
348
|
}
|
|
329
349
|
export declare class GPURenderPassEncoder implements globalThis.GPURenderPassEncoder {
|
|
@@ -343,7 +363,8 @@ export declare class GPURenderPassEncoder implements globalThis.GPURenderPassEnc
|
|
|
343
363
|
pushDebugGroup(groupLabel: string): undefined;
|
|
344
364
|
popDebugGroup(): undefined;
|
|
345
365
|
insertDebugMarker(markerLabel: string): undefined;
|
|
346
|
-
setBindGroup(index:
|
|
366
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsets?: Iterable<GPUBufferDynamicOffset>): undefined;
|
|
367
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null | undefined, dynamicOffsetsData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): undefined;
|
|
347
368
|
setImmediates(rangeOffset: GPUSize32, data: GPUAllowSharedBufferSource, dataOffset?: GPUSize64, dataSize?: GPUSize64): undefined;
|
|
348
369
|
setPipeline(pipeline: GPURenderPipeline): undefined;
|
|
349
370
|
setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
|
package/dist/webgpu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as gfx from 'wasi:webgpu/webgpu@0.3.0-rc.2';
|
|
2
|
-
import { EventTarget, inner, key, privateConstructorCalled, Todo, Unreachable } from './common';
|
|
2
|
+
import { EventTarget, inner, key, privateConstructorCalled, Todo, Unimplemented, Unreachable } from './common';
|
|
3
3
|
// flags converters: the web API uses numeric bitflags, wasi uses flag records.
|
|
4
4
|
function convertBufferUsageWebToWasi(usage) {
|
|
5
5
|
return {
|
|
@@ -335,7 +335,6 @@ function convertGpuLayoutWasiToWeb(layout) {
|
|
|
335
335
|
throw new Todo;
|
|
336
336
|
}
|
|
337
337
|
function convertColorWebToWasi(color) {
|
|
338
|
-
// https://www.w3.org/TR/webgpu/#colors-and-vectors
|
|
339
338
|
if (Symbol.iterator in color) {
|
|
340
339
|
const iter = color[Symbol.iterator]();
|
|
341
340
|
const r = iter.next().value;
|
|
@@ -343,6 +342,8 @@ function convertColorWebToWasi(color) {
|
|
|
343
342
|
const b = iter.next().value;
|
|
344
343
|
const a = iter.next().value;
|
|
345
344
|
if (r === undefined || g === undefined || b === undefined || a === undefined || !iter.next().done)
|
|
345
|
+
// https://www.w3.org/TR/webgpu/#abstract-opdef-validate-gpucolor-shape
|
|
346
|
+
// > Throw a TypeError if color is a sequence and color.size ≠ 4.
|
|
346
347
|
throw new TypeError("color must have exactly 4 items");
|
|
347
348
|
return {
|
|
348
349
|
r, g, b, a,
|
|
@@ -353,7 +354,7 @@ function convertColorWebToWasi(color) {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
function convertExtent3DWebToWasi(extent) {
|
|
356
|
-
//
|
|
357
|
+
// https://www.w3.org/TR/webgpu/#gpuextent3d-width
|
|
357
358
|
if (Symbol.iterator in extent) {
|
|
358
359
|
const iter = extent[Symbol.iterator]();
|
|
359
360
|
const width = iter.next().value;
|
|
@@ -372,14 +373,14 @@ function convertExtent3DWebToWasi(extent) {
|
|
|
372
373
|
}
|
|
373
374
|
}
|
|
374
375
|
function convertOrigin3DWebToWasi(origin) {
|
|
375
|
-
//
|
|
376
|
+
// Missing sequence items default to 0: https://www.w3.org/TR/webgpu/#gpuorigin3d-x
|
|
376
377
|
if (Symbol.iterator in origin) {
|
|
377
378
|
const iter = origin[Symbol.iterator]();
|
|
378
|
-
const x = iter.next().value;
|
|
379
|
-
const y = iter.next().value;
|
|
380
|
-
const z = iter.next().value;
|
|
381
|
-
if (
|
|
382
|
-
throw new TypeError("origin must have
|
|
379
|
+
const x = iter.next().value ?? 0;
|
|
380
|
+
const y = iter.next().value ?? 0;
|
|
381
|
+
const z = iter.next().value ?? 0;
|
|
382
|
+
if (!iter.next().done)
|
|
383
|
+
throw new TypeError("origin must have at most 3 items");
|
|
383
384
|
return {
|
|
384
385
|
x,
|
|
385
386
|
y,
|
|
@@ -439,6 +440,105 @@ function convertGpuErrorWasiToWeb(err) {
|
|
|
439
440
|
throw new Unreachable();
|
|
440
441
|
}
|
|
441
442
|
}
|
|
443
|
+
function convertRequestDeviceErrorWasiToWeb(err) {
|
|
444
|
+
const kind = err.kind;
|
|
445
|
+
switch (kind.tag) {
|
|
446
|
+
case "type-error":
|
|
447
|
+
return new TypeError(err.message);
|
|
448
|
+
case "operation-error":
|
|
449
|
+
return new DOMException(err.message, "OperationError");
|
|
450
|
+
default:
|
|
451
|
+
kind;
|
|
452
|
+
throw new Unreachable;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function convertCreatePipelineErrorWasiToWeb(err) {
|
|
456
|
+
const kind = err.kind;
|
|
457
|
+
switch (kind.tag) {
|
|
458
|
+
case "gpu-pipeline-error":
|
|
459
|
+
return new GPUPipelineError(err.message, { reason: kind.val });
|
|
460
|
+
default:
|
|
461
|
+
kind.tag;
|
|
462
|
+
throw new Unreachable;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function convertComputePipelineDescriptorWebToWasi(descriptor) {
|
|
466
|
+
return {
|
|
467
|
+
...descriptor,
|
|
468
|
+
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
469
|
+
compute: {
|
|
470
|
+
module: descriptor.compute.module[inner],
|
|
471
|
+
entryPoint: descriptor.compute.entryPoint,
|
|
472
|
+
constants: convertConstantsWebToWasi(descriptor.compute.constants),
|
|
473
|
+
},
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function convertRenderPipelineDescriptorWebToWasi(descriptor) {
|
|
477
|
+
let buffers = undefined;
|
|
478
|
+
if (descriptor.vertex.buffers) {
|
|
479
|
+
buffers = Array.from(descriptor.vertex.buffers).map(vbl => {
|
|
480
|
+
if (vbl) {
|
|
481
|
+
return {
|
|
482
|
+
...vbl,
|
|
483
|
+
arrayStride: numToBigInt(vbl.arrayStride),
|
|
484
|
+
attributes: Array.from(vbl.attributes).map(attribute => {
|
|
485
|
+
return {
|
|
486
|
+
...attribute,
|
|
487
|
+
offset: numToBigInt(attribute.offset),
|
|
488
|
+
format: convertVertexFormatWebToWasi(attribute.format),
|
|
489
|
+
};
|
|
490
|
+
}),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
const vertex = {
|
|
499
|
+
...descriptor.vertex,
|
|
500
|
+
constants: convertConstantsWebToWasi(descriptor.vertex.constants),
|
|
501
|
+
module: descriptor.vertex.module[inner],
|
|
502
|
+
buffers,
|
|
503
|
+
};
|
|
504
|
+
let depthStencil;
|
|
505
|
+
if (descriptor.depthStencil) {
|
|
506
|
+
depthStencil = {
|
|
507
|
+
...descriptor.depthStencil,
|
|
508
|
+
format: convertTextureFormatWebToWasi(descriptor.depthStencil.format),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
let fragment;
|
|
512
|
+
if (descriptor.fragment) {
|
|
513
|
+
fragment = {
|
|
514
|
+
...descriptor.fragment,
|
|
515
|
+
constants: convertConstantsWebToWasi(descriptor.fragment.constants),
|
|
516
|
+
module: descriptor.fragment.module[inner],
|
|
517
|
+
targets: Array.from(descriptor.fragment.targets).map(target => {
|
|
518
|
+
if (target) {
|
|
519
|
+
let writeMask;
|
|
520
|
+
if (target.writeMask !== undefined)
|
|
521
|
+
writeMask = convertColorWriteWebToWasi(target.writeMask);
|
|
522
|
+
return {
|
|
523
|
+
...target,
|
|
524
|
+
format: convertTextureFormatWebToWasi(target.format),
|
|
525
|
+
writeMask,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
}),
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
...descriptor,
|
|
536
|
+
vertex,
|
|
537
|
+
depthStencil,
|
|
538
|
+
fragment,
|
|
539
|
+
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
540
|
+
};
|
|
541
|
+
}
|
|
442
542
|
function convertBufferToUint8Array(buffer) {
|
|
443
543
|
if (buffer instanceof Uint8Array) {
|
|
444
544
|
return buffer;
|
|
@@ -465,9 +565,40 @@ function convertBufferToUint8Array(buffer) {
|
|
|
465
565
|
throw new Unreachable;
|
|
466
566
|
}
|
|
467
567
|
}
|
|
568
|
+
// helpers
|
|
569
|
+
function setBindGroup(encoder, index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
570
|
+
let bindGroupGfx;
|
|
571
|
+
if (bindGroup)
|
|
572
|
+
bindGroupGfx = bindGroup[inner];
|
|
573
|
+
if ((dynamicOffsetsData === undefined || dynamicOffsetsData[Symbol.iterator]) && dynamicOffsetsDataStart === undefined && dynamicOffsetsDataLength === undefined) {
|
|
574
|
+
// overload:
|
|
575
|
+
// `undefined setBindGroup(GPUIndex32 index, GPUBindGroup? bindGroup, optional sequence<GPUBufferDynamicOffset> dynamicOffsets = []);`
|
|
576
|
+
let dynamicOffsetsDataGfx;
|
|
577
|
+
if (dynamicOffsetsData) {
|
|
578
|
+
if (dynamicOffsetsData instanceof Uint32Array) {
|
|
579
|
+
dynamicOffsetsDataGfx = dynamicOffsetsData;
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
dynamicOffsetsDataGfx = new Uint32Array(dynamicOffsetsData);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
encoder.setBindGroup(index, bindGroupGfx, dynamicOffsetsDataGfx, undefined, undefined);
|
|
586
|
+
}
|
|
587
|
+
else if (dynamicOffsetsData instanceof Uint32Array && typeof dynamicOffsetsDataStart === "number" && typeof dynamicOffsetsDataLength === "number") {
|
|
588
|
+
// overload:
|
|
589
|
+
// `undefined setBindGroup(GPUIndex32 index, GPUBindGroup? bindGroup, [AllowShared] Uint32Array dynamicOffsetsData, GPUSize64 dynamicOffsetsDataStart, GPUSize32 dynamicOffsetsDataLength);`
|
|
590
|
+
if (dynamicOffsetsDataStart + dynamicOffsetsDataLength > dynamicOffsetsData.length)
|
|
591
|
+
throw new RangeError("dynamicOffsetsDataStart + dynamicOffsetsDataLength exceeds dynamicOffsetsData.length");
|
|
592
|
+
encoder.setBindGroup(index, bindGroupGfx, dynamicOffsetsData, numToBigInt(dynamicOffsetsDataStart), dynamicOffsetsDataLength);
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
throw new Unreachable;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
468
598
|
// When forwarding a method to gfx.[type].[method], always pass down objects (like `...descriptor`) so that if new fields are added and tsc can catch it.
|
|
469
599
|
export class GPU {
|
|
470
600
|
[inner];
|
|
601
|
+
#wgslLanguageFeatures;
|
|
471
602
|
constructor(k, i) {
|
|
472
603
|
privateConstructorCalled(k);
|
|
473
604
|
this[inner] = i;
|
|
@@ -476,7 +607,9 @@ export class GPU {
|
|
|
476
607
|
return "GPU";
|
|
477
608
|
}
|
|
478
609
|
get wgslLanguageFeatures() {
|
|
479
|
-
|
|
610
|
+
if (!this.#wgslLanguageFeatures)
|
|
611
|
+
this.#wgslLanguageFeatures = new WGSLLanguageFeatures(key, this[inner].wgslLanguageFeatures());
|
|
612
|
+
return this.#wgslLanguageFeatures;
|
|
480
613
|
}
|
|
481
614
|
async requestAdapter(descriptor = {}) {
|
|
482
615
|
const adapter = await this[inner].requestAdapter(descriptor);
|
|
@@ -506,11 +639,18 @@ export class GPUAdapter {
|
|
|
506
639
|
requiredLimits.add(key, numToBigIntOptional(value));
|
|
507
640
|
}
|
|
508
641
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
642
|
+
try {
|
|
643
|
+
return new GPUDevice(key, await this[inner].requestDevice({
|
|
644
|
+
...descriptor,
|
|
645
|
+
requiredFeatures,
|
|
646
|
+
requiredLimits,
|
|
647
|
+
}));
|
|
648
|
+
}
|
|
649
|
+
catch (e) {
|
|
650
|
+
if (e instanceof Error && "payload" in e)
|
|
651
|
+
throw convertRequestDeviceErrorWasiToWeb(e.payload);
|
|
652
|
+
throw e;
|
|
653
|
+
}
|
|
514
654
|
}
|
|
515
655
|
requestAdapterInfo() {
|
|
516
656
|
throw new Todo();
|
|
@@ -564,6 +704,37 @@ export class GPUSupportedFeatures {
|
|
|
564
704
|
throw new Todo;
|
|
565
705
|
}
|
|
566
706
|
}
|
|
707
|
+
export class WGSLLanguageFeatures {
|
|
708
|
+
[inner];
|
|
709
|
+
constructor(k, i) {
|
|
710
|
+
privateConstructorCalled(k);
|
|
711
|
+
this[inner] = i;
|
|
712
|
+
}
|
|
713
|
+
get __brand() {
|
|
714
|
+
return "WGSLLanguageFeatures";
|
|
715
|
+
}
|
|
716
|
+
get size() {
|
|
717
|
+
throw new Todo;
|
|
718
|
+
}
|
|
719
|
+
has(value) {
|
|
720
|
+
return this[inner].has(value);
|
|
721
|
+
}
|
|
722
|
+
forEach(callbackfn, thisArg) {
|
|
723
|
+
throw new Todo;
|
|
724
|
+
}
|
|
725
|
+
entries() {
|
|
726
|
+
throw new Todo;
|
|
727
|
+
}
|
|
728
|
+
keys() {
|
|
729
|
+
throw new Todo;
|
|
730
|
+
}
|
|
731
|
+
values() {
|
|
732
|
+
throw new Todo;
|
|
733
|
+
}
|
|
734
|
+
[Symbol.iterator]() {
|
|
735
|
+
throw new Todo;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
567
738
|
export class GPUSupportedLimits {
|
|
568
739
|
[inner];
|
|
569
740
|
constructor(k, i) {
|
|
@@ -774,9 +945,19 @@ export class GPUDevice extends EventTarget {
|
|
|
774
945
|
this[inner].setLabel(value);
|
|
775
946
|
}
|
|
776
947
|
get lost() {
|
|
777
|
-
if (!this.#lost)
|
|
778
|
-
|
|
779
|
-
|
|
948
|
+
if (!this.#lost) {
|
|
949
|
+
// The generated types declare `lost()` as `PromiseLike`, but componentize-qjs returns a non-thenable future reader (`.read()` yields the value). So read it only if it isn't thenable.
|
|
950
|
+
// See https://github.com/bytecodealliance/jco/issues/2532
|
|
951
|
+
const lost = this[inner].lost();
|
|
952
|
+
let info;
|
|
953
|
+
if ('then' in lost && typeof lost.then === 'function') {
|
|
954
|
+
info = Promise.resolve(lost);
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
info = lost.read();
|
|
958
|
+
}
|
|
959
|
+
this.#lost = info.then(info => new GPUDeviceLostInfo(key, info));
|
|
960
|
+
}
|
|
780
961
|
return this.#lost;
|
|
781
962
|
}
|
|
782
963
|
get features() {
|
|
@@ -919,96 +1100,34 @@ export class GPUDevice extends EventTarget {
|
|
|
919
1100
|
}));
|
|
920
1101
|
}
|
|
921
1102
|
createComputePipeline(descriptor) {
|
|
922
|
-
|
|
923
|
-
module: descriptor.compute.module[inner],
|
|
924
|
-
entryPoint: descriptor.compute.entryPoint,
|
|
925
|
-
constants: convertConstantsWebToWasi(descriptor.compute.constants),
|
|
926
|
-
};
|
|
927
|
-
return new GPUComputePipeline(key, this[inner].createComputePipeline({
|
|
928
|
-
...descriptor,
|
|
929
|
-
compute,
|
|
930
|
-
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
931
|
-
}));
|
|
1103
|
+
return new GPUComputePipeline(key, this[inner].createComputePipeline(convertComputePipelineDescriptorWebToWasi(descriptor)));
|
|
932
1104
|
}
|
|
933
1105
|
createRenderPipeline(descriptor) {
|
|
934
|
-
|
|
935
|
-
if (descriptor.vertex.buffers) {
|
|
936
|
-
buffers = Array.from(descriptor.vertex.buffers).map(vbl => {
|
|
937
|
-
if (vbl) {
|
|
938
|
-
return {
|
|
939
|
-
...vbl,
|
|
940
|
-
arrayStride: numToBigInt(vbl.arrayStride),
|
|
941
|
-
attributes: Array.from(vbl.attributes).map(attribute => {
|
|
942
|
-
return {
|
|
943
|
-
...attribute,
|
|
944
|
-
offset: numToBigInt(attribute.offset),
|
|
945
|
-
format: convertVertexFormatWebToWasi(attribute.format),
|
|
946
|
-
};
|
|
947
|
-
}),
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
else {
|
|
951
|
-
return undefined;
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
const vertex = {
|
|
956
|
-
...descriptor.vertex,
|
|
957
|
-
constants: convertConstantsWebToWasi(descriptor.vertex.constants),
|
|
958
|
-
module: descriptor.vertex.module[inner],
|
|
959
|
-
buffers,
|
|
960
|
-
};
|
|
961
|
-
let depthStencil;
|
|
962
|
-
if (descriptor.depthStencil) {
|
|
963
|
-
depthStencil = {
|
|
964
|
-
...descriptor.depthStencil,
|
|
965
|
-
format: convertTextureFormatWebToWasi(descriptor.depthStencil.format),
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
let fragment;
|
|
969
|
-
if (descriptor.fragment) {
|
|
970
|
-
fragment = {
|
|
971
|
-
...descriptor.fragment,
|
|
972
|
-
constants: convertConstantsWebToWasi(descriptor.fragment.constants),
|
|
973
|
-
module: descriptor.fragment.module[inner],
|
|
974
|
-
targets: Array.from(descriptor.fragment.targets).map(target => {
|
|
975
|
-
if (target) {
|
|
976
|
-
let writeMask;
|
|
977
|
-
if (target.writeMask !== undefined)
|
|
978
|
-
writeMask = convertColorWriteWebToWasi(target.writeMask);
|
|
979
|
-
return {
|
|
980
|
-
...target,
|
|
981
|
-
format: convertTextureFormatWebToWasi(target.format),
|
|
982
|
-
writeMask,
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
return undefined;
|
|
987
|
-
}
|
|
988
|
-
}),
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
return new GPURenderPipeline(key, this[inner].createRenderPipeline({
|
|
992
|
-
...descriptor,
|
|
993
|
-
vertex,
|
|
994
|
-
depthStencil,
|
|
995
|
-
fragment,
|
|
996
|
-
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
997
|
-
}));
|
|
1106
|
+
return new GPURenderPipeline(key, this[inner].createRenderPipeline(convertRenderPipelineDescriptorWebToWasi(descriptor)));
|
|
998
1107
|
}
|
|
999
1108
|
async createComputePipelineAsync(descriptor) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1109
|
+
const gfxDescriptor = convertComputePipelineDescriptorWebToWasi(descriptor);
|
|
1110
|
+
try {
|
|
1111
|
+
const gfxPipeline = await this[inner].createComputePipelineAsync(gfxDescriptor);
|
|
1112
|
+
return new GPUComputePipeline(key, gfxPipeline);
|
|
1113
|
+
}
|
|
1114
|
+
catch (e) {
|
|
1115
|
+
if (e instanceof Error && "payload" in e)
|
|
1116
|
+
throw convertCreatePipelineErrorWasiToWeb(e.payload);
|
|
1117
|
+
throw e;
|
|
1118
|
+
}
|
|
1005
1119
|
}
|
|
1006
1120
|
async createRenderPipelineAsync(descriptor) {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1121
|
+
const gfxDescriptor = convertRenderPipelineDescriptorWebToWasi(descriptor);
|
|
1122
|
+
try {
|
|
1123
|
+
const gfxPipeline = await this[inner].createRenderPipelineAsync(gfxDescriptor);
|
|
1124
|
+
return new GPURenderPipeline(key, gfxPipeline);
|
|
1125
|
+
}
|
|
1126
|
+
catch (e) {
|
|
1127
|
+
if (e instanceof Error && "payload" in e)
|
|
1128
|
+
throw convertCreatePipelineErrorWasiToWeb(e.payload);
|
|
1129
|
+
throw e;
|
|
1130
|
+
}
|
|
1012
1131
|
}
|
|
1013
1132
|
createCommandEncoder(descriptor = {}) {
|
|
1014
1133
|
return new GPUCommandEncoder(key, this[inner].createCommandEncoder(descriptor));
|
|
@@ -1046,7 +1165,7 @@ export class GPUDevice extends EventTarget {
|
|
|
1046
1165
|
}
|
|
1047
1166
|
}
|
|
1048
1167
|
importExternalTexture(descriptor) {
|
|
1049
|
-
throw new
|
|
1168
|
+
throw new Unimplemented;
|
|
1050
1169
|
}
|
|
1051
1170
|
onuncapturederror = null;
|
|
1052
1171
|
}
|
|
@@ -1081,7 +1200,7 @@ export class GPURenderBundleEncoder {
|
|
|
1081
1200
|
this[inner].insertDebugMarker(markerLabel);
|
|
1082
1201
|
}
|
|
1083
1202
|
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1084
|
-
|
|
1203
|
+
setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
|
|
1085
1204
|
}
|
|
1086
1205
|
setPipeline(pipeline) {
|
|
1087
1206
|
this[inner].setPipeline(pipeline[inner]);
|
|
@@ -1459,6 +1578,16 @@ export class GPUTexture {
|
|
|
1459
1578
|
this[inner].destroy();
|
|
1460
1579
|
}
|
|
1461
1580
|
}
|
|
1581
|
+
// wasi:webgpu has no external texture, so this is never constructed. It exists so `instanceof GPUExternalTexture` in WebGPU spec tests works.
|
|
1582
|
+
export class GPUExternalTexture {
|
|
1583
|
+
constructor(k) {
|
|
1584
|
+
privateConstructorCalled(k);
|
|
1585
|
+
}
|
|
1586
|
+
get __brand() {
|
|
1587
|
+
return "GPUExternalTexture";
|
|
1588
|
+
}
|
|
1589
|
+
label = "";
|
|
1590
|
+
}
|
|
1462
1591
|
export class GPUCommandEncoder {
|
|
1463
1592
|
[inner];
|
|
1464
1593
|
constructor(k, i) {
|
|
@@ -1629,27 +1758,7 @@ export class GPUComputePassEncoder {
|
|
|
1629
1758
|
this[inner].insertDebugMarker(markerLabel);
|
|
1630
1759
|
}
|
|
1631
1760
|
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1632
|
-
|
|
1633
|
-
if (bindGroup)
|
|
1634
|
-
bindGroupGfx = bindGroup[inner];
|
|
1635
|
-
if ((dynamicOffsetsData === undefined || dynamicOffsetsData[Symbol.iterator]) && dynamicOffsetsDataStart === undefined && dynamicOffsetsDataLength === undefined) {
|
|
1636
|
-
let dynamicOffsetsDataGfx;
|
|
1637
|
-
if (dynamicOffsetsData) {
|
|
1638
|
-
if (dynamicOffsetsData instanceof Uint32Array) {
|
|
1639
|
-
dynamicOffsetsDataGfx = dynamicOffsetsData;
|
|
1640
|
-
}
|
|
1641
|
-
else {
|
|
1642
|
-
dynamicOffsetsDataGfx = new Uint32Array(dynamicOffsetsData);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsDataGfx, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
|
|
1646
|
-
}
|
|
1647
|
-
else if (dynamicOffsetsData instanceof Uint32Array && typeof dynamicOffsetsDataStart === "number" && typeof dynamicOffsetsDataLength === "number") {
|
|
1648
|
-
this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsData, numToBigInt(dynamicOffsetsDataStart), dynamicOffsetsDataLength);
|
|
1649
|
-
}
|
|
1650
|
-
else {
|
|
1651
|
-
throw new Todo;
|
|
1652
|
-
}
|
|
1761
|
+
setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
|
|
1653
1762
|
}
|
|
1654
1763
|
setImmediates(rangeOffset, data, dataOffset, dataSize) {
|
|
1655
1764
|
this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
|
|
@@ -1704,7 +1813,7 @@ export class GPURenderPassEncoder {
|
|
|
1704
1813
|
this[inner].insertDebugMarker(markerLabel);
|
|
1705
1814
|
}
|
|
1706
1815
|
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1707
|
-
|
|
1816
|
+
setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
|
|
1708
1817
|
}
|
|
1709
1818
|
setImmediates(rangeOffset, data, dataOffset, dataSize) {
|
|
1710
1819
|
this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
|