@wasi-gfx/js-webgpu 0.4.1 → 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 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: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
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, dynamicOffsetsData?: Iterable<GPUBufferDynamicOffset> | Uint32Array, dynamicOffsetsDataStart?: GPUSize64, dynamicOffsetsDataLength?: GPUSize32): undefined;
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: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
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
- // TODO: add correct link https://www.w3.org/TR/webgpu/#colors-and-vectors
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
- // TODO: add correct link https://www.w3.org/TR/webgpu/#colors-and-vectors
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 (x === undefined || y === undefined || z === undefined || !iter.next().done)
382
- throw new TypeError("origin must have exactly 3 items");
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
- throw new Todo;
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
- return new GPUDevice(key, await this[inner].requestDevice({
510
- ...descriptor,
511
- requiredFeatures,
512
- requiredLimits,
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) {
@@ -929,96 +1100,34 @@ export class GPUDevice extends EventTarget {
929
1100
  }));
930
1101
  }
931
1102
  createComputePipeline(descriptor) {
932
- let compute = {
933
- module: descriptor.compute.module[inner],
934
- entryPoint: descriptor.compute.entryPoint,
935
- constants: convertConstantsWebToWasi(descriptor.compute.constants),
936
- };
937
- return new GPUComputePipeline(key, this[inner].createComputePipeline({
938
- ...descriptor,
939
- compute,
940
- layout: convertGpuLayoutWebToWasi(descriptor.layout),
941
- }));
1103
+ return new GPUComputePipeline(key, this[inner].createComputePipeline(convertComputePipelineDescriptorWebToWasi(descriptor)));
942
1104
  }
943
1105
  createRenderPipeline(descriptor) {
944
- let buffers = undefined;
945
- if (descriptor.vertex.buffers) {
946
- buffers = Array.from(descriptor.vertex.buffers).map(vbl => {
947
- if (vbl) {
948
- return {
949
- ...vbl,
950
- arrayStride: numToBigInt(vbl.arrayStride),
951
- attributes: Array.from(vbl.attributes).map(attribute => {
952
- return {
953
- ...attribute,
954
- offset: numToBigInt(attribute.offset),
955
- format: convertVertexFormatWebToWasi(attribute.format),
956
- };
957
- }),
958
- };
959
- }
960
- else {
961
- return undefined;
962
- }
963
- });
964
- }
965
- const vertex = {
966
- ...descriptor.vertex,
967
- constants: convertConstantsWebToWasi(descriptor.vertex.constants),
968
- module: descriptor.vertex.module[inner],
969
- buffers,
970
- };
971
- let depthStencil;
972
- if (descriptor.depthStencil) {
973
- depthStencil = {
974
- ...descriptor.depthStencil,
975
- format: convertTextureFormatWebToWasi(descriptor.depthStencil.format),
976
- };
977
- }
978
- let fragment;
979
- if (descriptor.fragment) {
980
- fragment = {
981
- ...descriptor.fragment,
982
- constants: convertConstantsWebToWasi(descriptor.fragment.constants),
983
- module: descriptor.fragment.module[inner],
984
- targets: Array.from(descriptor.fragment.targets).map(target => {
985
- if (target) {
986
- let writeMask;
987
- if (target.writeMask !== undefined)
988
- writeMask = convertColorWriteWebToWasi(target.writeMask);
989
- return {
990
- ...target,
991
- format: convertTextureFormatWebToWasi(target.format),
992
- writeMask,
993
- };
994
- }
995
- else {
996
- return undefined;
997
- }
998
- }),
999
- };
1000
- }
1001
- return new GPURenderPipeline(key, this[inner].createRenderPipeline({
1002
- ...descriptor,
1003
- vertex,
1004
- depthStencil,
1005
- fragment,
1006
- layout: convertGpuLayoutWebToWasi(descriptor.layout),
1007
- }));
1106
+ return new GPURenderPipeline(key, this[inner].createRenderPipeline(convertRenderPipelineDescriptorWebToWasi(descriptor)));
1008
1107
  }
1009
1108
  async createComputePipelineAsync(descriptor) {
1010
- // TODO: make this really async
1011
- await Promise.resolve();
1012
- const result = this.createComputePipeline(descriptor);
1013
- await Promise.resolve();
1014
- return result;
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
+ }
1015
1119
  }
1016
1120
  async createRenderPipelineAsync(descriptor) {
1017
- // TODO: make this really async
1018
- await Promise.resolve();
1019
- const result = this.createRenderPipeline(descriptor);
1020
- await Promise.resolve();
1021
- return result;
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
+ }
1022
1131
  }
1023
1132
  createCommandEncoder(descriptor = {}) {
1024
1133
  return new GPUCommandEncoder(key, this[inner].createCommandEncoder(descriptor));
@@ -1056,7 +1165,7 @@ export class GPUDevice extends EventTarget {
1056
1165
  }
1057
1166
  }
1058
1167
  importExternalTexture(descriptor) {
1059
- throw new Todo;
1168
+ throw new Unimplemented;
1060
1169
  }
1061
1170
  onuncapturederror = null;
1062
1171
  }
@@ -1091,7 +1200,7 @@ export class GPURenderBundleEncoder {
1091
1200
  this[inner].insertDebugMarker(markerLabel);
1092
1201
  }
1093
1202
  setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
1094
- throw new Todo;
1203
+ setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
1095
1204
  }
1096
1205
  setPipeline(pipeline) {
1097
1206
  this[inner].setPipeline(pipeline[inner]);
@@ -1469,6 +1578,16 @@ export class GPUTexture {
1469
1578
  this[inner].destroy();
1470
1579
  }
1471
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
+ }
1472
1591
  export class GPUCommandEncoder {
1473
1592
  [inner];
1474
1593
  constructor(k, i) {
@@ -1639,27 +1758,7 @@ export class GPUComputePassEncoder {
1639
1758
  this[inner].insertDebugMarker(markerLabel);
1640
1759
  }
1641
1760
  setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
1642
- let bindGroupGfx;
1643
- if (bindGroup)
1644
- bindGroupGfx = bindGroup[inner];
1645
- if ((dynamicOffsetsData === undefined || dynamicOffsetsData[Symbol.iterator]) && dynamicOffsetsDataStart === undefined && dynamicOffsetsDataLength === undefined) {
1646
- let dynamicOffsetsDataGfx;
1647
- if (dynamicOffsetsData) {
1648
- if (dynamicOffsetsData instanceof Uint32Array) {
1649
- dynamicOffsetsDataGfx = dynamicOffsetsData;
1650
- }
1651
- else {
1652
- dynamicOffsetsDataGfx = new Uint32Array(dynamicOffsetsData);
1653
- }
1654
- }
1655
- this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsDataGfx, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
1656
- }
1657
- else if (dynamicOffsetsData instanceof Uint32Array && typeof dynamicOffsetsDataStart === "number" && typeof dynamicOffsetsDataLength === "number") {
1658
- this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsData, numToBigInt(dynamicOffsetsDataStart), dynamicOffsetsDataLength);
1659
- }
1660
- else {
1661
- throw new Todo;
1662
- }
1761
+ setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
1663
1762
  }
1664
1763
  setImmediates(rangeOffset, data, dataOffset, dataSize) {
1665
1764
  this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
@@ -1714,7 +1813,7 @@ export class GPURenderPassEncoder {
1714
1813
  this[inner].insertDebugMarker(markerLabel);
1715
1814
  }
1716
1815
  setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
1717
- throw new Todo;
1816
+ setBindGroup(this[inner], index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
1718
1817
  }
1719
1818
  setImmediates(rangeOffset, data, dataOffset, dataSize) {
1720
1819
  this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wasi-gfx/js-webgpu",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "WebGPU JavaScript API on top of wasi-gfx",
5
5
  "exports": {
6
6
  "./canvas": {