@wasi-gfx/js-webgpu 0.3.0 → 0.4.0
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 +12 -10
- package/dist/webgpu.d.ts +29 -0
- package/dist/webgpu.js +95 -9
- package/package.json +1 -1
package/dist/globals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getGpu, GPU, GPUAdapter, GPUDevice, GPUQueue, GPUBuffer, GPUBufferUsage, GPUMapMode, GPUTextureUsage, GPUTexture, GPUTextureView, GPUSampler, GPUBindGroupLayout, GPUPipelineLayout, GPUBindGroup, GPUShaderModule, GPUShaderStage, GPUComputePipeline, GPURenderPipeline, GPUColorWrite, GPUCommandEncoder, GPURenderPassEncoder, GPUComputePassEncoder, GPUCommandBuffer, GPUQuerySet } from "./webgpu";
|
|
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";
|
|
2
2
|
class Navigator {
|
|
3
3
|
gpu;
|
|
4
4
|
constructor() {
|
|
@@ -18,10 +18,10 @@ export function declareGlobals() {
|
|
|
18
18
|
defineGlobal("navigator", new Navigator());
|
|
19
19
|
defineGlobal("GPU", GPU);
|
|
20
20
|
defineGlobal("GPUAdapter", GPUAdapter);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
defineGlobal("GPUAdapterInfo", GPUAdapterInfo);
|
|
22
|
+
defineGlobal("GPUSupportedLimits", GPUSupportedLimits);
|
|
23
|
+
defineGlobal("GPUSupportedFeatures", GPUSupportedFeatures);
|
|
24
|
+
defineGlobal("GPUDeviceLostInfo", GPUDeviceLostInfo);
|
|
25
25
|
defineGlobal("GPUDevice", GPUDevice);
|
|
26
26
|
defineGlobal("GPUQueue", GPUQueue);
|
|
27
27
|
defineGlobal("GPUBuffer", GPUBuffer);
|
|
@@ -43,10 +43,12 @@ export function declareGlobals() {
|
|
|
43
43
|
defineGlobal("GPURenderPassEncoder", GPURenderPassEncoder);
|
|
44
44
|
defineGlobal("GPUComputePassEncoder", GPUComputePassEncoder);
|
|
45
45
|
defineGlobal("GPUCommandBuffer", GPUCommandBuffer);
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
defineGlobal("GPURenderBundleEncoder", GPURenderBundleEncoder);
|
|
47
|
+
defineGlobal("GPURenderBundle", GPURenderBundle);
|
|
48
48
|
defineGlobal("GPUQuerySet", GPUQuerySet);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
defineGlobal("GPUError", GPUError);
|
|
50
|
+
defineGlobal("GPUValidationError", GPUValidationError);
|
|
51
|
+
defineGlobal("GPUOutOfMemoryError", GPUOutOfMemoryError);
|
|
52
|
+
defineGlobal("GPUInternalError", GPUInternalError);
|
|
53
|
+
defineGlobal("GPUPipelineError", GPUPipelineError);
|
|
52
54
|
}
|
package/dist/webgpu.d.ts
CHANGED
|
@@ -80,6 +80,35 @@ export declare class GPUAdapterInfo implements globalThis.GPUAdapterInfo {
|
|
|
80
80
|
get description(): string;
|
|
81
81
|
get isFallbackAdapter(): boolean;
|
|
82
82
|
}
|
|
83
|
+
export declare class GPUDeviceLostInfo implements globalThis.GPUDeviceLostInfo {
|
|
84
|
+
[inner]: gfx.GpuDeviceLostInfo;
|
|
85
|
+
constructor(k: symbol, i: gfx.GpuDeviceLostInfo);
|
|
86
|
+
get __brand(): 'GPUDeviceLostInfo';
|
|
87
|
+
get reason(): GPUDeviceLostReason;
|
|
88
|
+
get message(): string;
|
|
89
|
+
}
|
|
90
|
+
export declare class GPUError implements globalThis.GPUError {
|
|
91
|
+
#private;
|
|
92
|
+
constructor(k: symbol, message: string);
|
|
93
|
+
get message(): string;
|
|
94
|
+
}
|
|
95
|
+
export declare class GPUValidationError extends GPUError implements globalThis.GPUValidationError {
|
|
96
|
+
constructor(message: string);
|
|
97
|
+
get __brand(): 'GPUValidationError';
|
|
98
|
+
}
|
|
99
|
+
export declare class GPUOutOfMemoryError extends GPUError implements globalThis.GPUOutOfMemoryError {
|
|
100
|
+
constructor(message: string);
|
|
101
|
+
get __brand(): 'GPUOutOfMemoryError';
|
|
102
|
+
}
|
|
103
|
+
export declare class GPUInternalError extends GPUError implements globalThis.GPUInternalError {
|
|
104
|
+
constructor(message: string);
|
|
105
|
+
get __brand(): 'GPUInternalError';
|
|
106
|
+
}
|
|
107
|
+
export declare class GPUPipelineError extends DOMException implements globalThis.GPUPipelineError {
|
|
108
|
+
readonly reason: GPUPipelineErrorReason;
|
|
109
|
+
constructor(message: string | undefined, options: GPUPipelineErrorInit);
|
|
110
|
+
get __brand(): 'GPUPipelineError';
|
|
111
|
+
}
|
|
83
112
|
export declare class GPUDevice extends EventTarget implements globalThis.GPUDevice {
|
|
84
113
|
#private;
|
|
85
114
|
[inner]: gfx.GpuDevice;
|
package/dist/webgpu.js
CHANGED
|
@@ -306,6 +306,15 @@ function convertTextureViewDimensionWasiToWeb(name) {
|
|
|
306
306
|
return name;
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
+
function convertConstantsWebToWasi(constants) {
|
|
310
|
+
if (constants === undefined)
|
|
311
|
+
return undefined;
|
|
312
|
+
const record = new gfx.RecordGpuPipelineConstantValue();
|
|
313
|
+
for (const [key, value] of Object.entries(constants)) {
|
|
314
|
+
record.add(key, value);
|
|
315
|
+
}
|
|
316
|
+
return record;
|
|
317
|
+
}
|
|
309
318
|
function convertGpuLayoutWebToWasi(layout) {
|
|
310
319
|
if (layout instanceof GPUPipelineLayout) {
|
|
311
320
|
return {
|
|
@@ -415,6 +424,21 @@ function convertGpuBindingResourceWebToWasi(resource) {
|
|
|
415
424
|
throw new Unreachable;
|
|
416
425
|
}
|
|
417
426
|
}
|
|
427
|
+
function convertGpuErrorWasiToWeb(err) {
|
|
428
|
+
const message = err.message();
|
|
429
|
+
const kind = err.kind();
|
|
430
|
+
switch (kind.tag) {
|
|
431
|
+
case "validation-error":
|
|
432
|
+
return new GPUValidationError(message);
|
|
433
|
+
case "out-of-memory-error":
|
|
434
|
+
return new GPUOutOfMemoryError(message);
|
|
435
|
+
case "internal-error":
|
|
436
|
+
return new GPUInternalError(message);
|
|
437
|
+
default:
|
|
438
|
+
kind;
|
|
439
|
+
throw new Unreachable();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
418
442
|
function convertBufferToUint8Array(buffer) {
|
|
419
443
|
if (buffer instanceof Uint8Array) {
|
|
420
444
|
return buffer;
|
|
@@ -671,9 +695,70 @@ export class GPUAdapterInfo {
|
|
|
671
695
|
return this[inner].isFallbackAdapter();
|
|
672
696
|
}
|
|
673
697
|
}
|
|
698
|
+
export class GPUDeviceLostInfo {
|
|
699
|
+
[inner];
|
|
700
|
+
constructor(k, i) {
|
|
701
|
+
privateConstructorCalled(k);
|
|
702
|
+
this[inner] = i;
|
|
703
|
+
}
|
|
704
|
+
get __brand() {
|
|
705
|
+
return "GPUDeviceLostInfo";
|
|
706
|
+
}
|
|
707
|
+
get reason() {
|
|
708
|
+
return this[inner].reason();
|
|
709
|
+
}
|
|
710
|
+
get message() {
|
|
711
|
+
return this[inner].message();
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
export class GPUError {
|
|
715
|
+
#message;
|
|
716
|
+
constructor(k, message) {
|
|
717
|
+
privateConstructorCalled(k);
|
|
718
|
+
this.#message = message;
|
|
719
|
+
}
|
|
720
|
+
get message() {
|
|
721
|
+
return this.#message;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
export class GPUValidationError extends GPUError {
|
|
725
|
+
constructor(message) {
|
|
726
|
+
super(key, message);
|
|
727
|
+
}
|
|
728
|
+
get __brand() {
|
|
729
|
+
return "GPUValidationError";
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
export class GPUOutOfMemoryError extends GPUError {
|
|
733
|
+
constructor(message) {
|
|
734
|
+
super(key, message);
|
|
735
|
+
}
|
|
736
|
+
get __brand() {
|
|
737
|
+
return "GPUOutOfMemoryError";
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
export class GPUInternalError extends GPUError {
|
|
741
|
+
constructor(message) {
|
|
742
|
+
super(key, message);
|
|
743
|
+
}
|
|
744
|
+
get __brand() {
|
|
745
|
+
return "GPUInternalError";
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
export class GPUPipelineError extends DOMException {
|
|
749
|
+
reason;
|
|
750
|
+
constructor(message = "", options) {
|
|
751
|
+
super(message, "GPUPipelineError");
|
|
752
|
+
this.reason = options.reason;
|
|
753
|
+
}
|
|
754
|
+
get __brand() {
|
|
755
|
+
return "GPUPipelineError";
|
|
756
|
+
}
|
|
757
|
+
}
|
|
674
758
|
export class GPUDevice extends EventTarget {
|
|
675
759
|
[inner];
|
|
676
760
|
#adapterInfo;
|
|
761
|
+
#lost;
|
|
677
762
|
constructor(k, i) {
|
|
678
763
|
privateConstructorCalled(k);
|
|
679
764
|
super();
|
|
@@ -689,7 +774,10 @@ export class GPUDevice extends EventTarget {
|
|
|
689
774
|
this[inner].setLabel(value);
|
|
690
775
|
}
|
|
691
776
|
get lost() {
|
|
692
|
-
|
|
777
|
+
if (!this.#lost)
|
|
778
|
+
this.#lost = Promise.resolve(this[inner].lost())
|
|
779
|
+
.then(info => new GPUDeviceLostInfo(key, info));
|
|
780
|
+
return this.#lost;
|
|
693
781
|
}
|
|
694
782
|
get features() {
|
|
695
783
|
return new GPUSupportedFeatures(key, this[inner].features());
|
|
@@ -834,7 +922,7 @@ export class GPUDevice extends EventTarget {
|
|
|
834
922
|
let compute = {
|
|
835
923
|
module: descriptor.compute.module[inner],
|
|
836
924
|
entryPoint: descriptor.compute.entryPoint,
|
|
837
|
-
constants:
|
|
925
|
+
constants: convertConstantsWebToWasi(descriptor.compute.constants),
|
|
838
926
|
};
|
|
839
927
|
return new GPUComputePipeline(key, this[inner].createComputePipeline({
|
|
840
928
|
...descriptor,
|
|
@@ -866,7 +954,7 @@ export class GPUDevice extends EventTarget {
|
|
|
866
954
|
}
|
|
867
955
|
const vertex = {
|
|
868
956
|
...descriptor.vertex,
|
|
869
|
-
constants:
|
|
957
|
+
constants: convertConstantsWebToWasi(descriptor.vertex.constants),
|
|
870
958
|
module: descriptor.vertex.module[inner],
|
|
871
959
|
buffers,
|
|
872
960
|
};
|
|
@@ -881,7 +969,7 @@ export class GPUDevice extends EventTarget {
|
|
|
881
969
|
if (descriptor.fragment) {
|
|
882
970
|
fragment = {
|
|
883
971
|
...descriptor.fragment,
|
|
884
|
-
constants:
|
|
972
|
+
constants: convertConstantsWebToWasi(descriptor.fragment.constants),
|
|
885
973
|
module: descriptor.fragment.module[inner],
|
|
886
974
|
targets: Array.from(descriptor.fragment.targets).map(target => {
|
|
887
975
|
if (target) {
|
|
@@ -951,9 +1039,7 @@ export class GPUDevice extends EventTarget {
|
|
|
951
1039
|
async popErrorScope() {
|
|
952
1040
|
const err = await this[inner].popErrorScope();
|
|
953
1041
|
if (err) {
|
|
954
|
-
return
|
|
955
|
-
message: err.message(),
|
|
956
|
-
};
|
|
1042
|
+
return convertGpuErrorWasiToWeb(err);
|
|
957
1043
|
}
|
|
958
1044
|
else {
|
|
959
1045
|
return null;
|
|
@@ -1220,8 +1306,8 @@ export class GPUQueue {
|
|
|
1220
1306
|
submit(commandBuffers) {
|
|
1221
1307
|
this[inner].submit(Array.from(commandBuffers).map((cb) => cb[inner]));
|
|
1222
1308
|
}
|
|
1223
|
-
onSubmittedWorkDone() {
|
|
1224
|
-
|
|
1309
|
+
async onSubmittedWorkDone() {
|
|
1310
|
+
await this[inner].onSubmittedWorkDone();
|
|
1225
1311
|
}
|
|
1226
1312
|
writeBuffer(buffer, bufferOffset, data, dataOffset, size) {
|
|
1227
1313
|
this[inner].writeBufferWithCopy(buffer[inner], numToBigInt(bufferOffset), convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(size));
|