@wasi-gfx/js-webgpu 0.1.0 → 0.2.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/canvas.d.ts +45 -0
- package/dist/canvas.js +112 -0
- package/dist/common.d.ts +17 -0
- package/dist/common.js +33 -0
- package/dist/globals.d.ts +1 -0
- package/dist/globals.js +52 -0
- package/dist/webgpu.d.ts +353 -0
- package/dist/{index.js → webgpu.js} +2 -142
- package/package.json +15 -2
package/dist/canvas.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as wasiSurface from 'wasi:surface/surface@0.0.1';
|
|
2
|
+
import * as wasiGraphicsContext from 'wasi:graphics-context/graphics-context@0.0.1';
|
|
3
|
+
import { GPUTexture } from './webgpu';
|
|
4
|
+
export declare function createCanvas(): HTMLCanvasElement;
|
|
5
|
+
type LimitedCanvas = Pick<globalThis.HTMLCanvasElement, "height" | "width" | "getContext" | "transferControlToOffscreen" | "addEventListener" | "removeEventListener" | "dispatchEvent" | "onclick" | "ondblclick" | "oninput" | "onkeydown" | "onkeyup" | "onpointerdown" | "onpointermove" | "onpointerup">;
|
|
6
|
+
export declare class HTMLCanvasElement implements LimitedCanvas, AnimationFrameProvider {
|
|
7
|
+
#private;
|
|
8
|
+
_surface: wasiSurface.Surface;
|
|
9
|
+
_graphicsContext: wasiGraphicsContext.Context;
|
|
10
|
+
get height(): number;
|
|
11
|
+
set height(value: number);
|
|
12
|
+
get width(): number;
|
|
13
|
+
set width(value: number);
|
|
14
|
+
constructor(k: symbol);
|
|
15
|
+
getContext(contextId: "2d", options?: CanvasRenderingContext2DSettings | undefined): CanvasRenderingContext2D | null;
|
|
16
|
+
getContext(contextId: "bitmaprenderer", options?: ImageBitmapRenderingContextSettings | undefined): ImageBitmapRenderingContext | null;
|
|
17
|
+
getContext(contextId: "webgl", options?: WebGLContextAttributes | undefined): WebGLRenderingContext | null;
|
|
18
|
+
getContext(contextId: "webgl2", options?: WebGLContextAttributes | undefined): WebGL2RenderingContext | null;
|
|
19
|
+
getContext(contextId: "webgpu"): GPUCanvasContext;
|
|
20
|
+
transferControlToOffscreen(): OffscreenCanvas;
|
|
21
|
+
addEventListener(type: unknown, listener: unknown, options?: unknown): void;
|
|
22
|
+
removeEventListener(type: unknown, listener: unknown, options?: unknown): void;
|
|
23
|
+
dispatchEvent(event: Event): boolean;
|
|
24
|
+
onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
25
|
+
ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
26
|
+
oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
27
|
+
onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
28
|
+
onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
29
|
+
onpointerdown: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
30
|
+
onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
31
|
+
onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
32
|
+
cancelAnimationFrame(handle: number): void;
|
|
33
|
+
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
34
|
+
}
|
|
35
|
+
export declare class GPUCanvasContext implements globalThis.GPUCanvasContext {
|
|
36
|
+
#private;
|
|
37
|
+
constructor(k: symbol, canvas: HTMLCanvasElement);
|
|
38
|
+
readonly __brand: 'GPUCanvasContext';
|
|
39
|
+
get canvas(): globalThis.HTMLCanvasElement;
|
|
40
|
+
configure(configuration: GPUCanvasConfiguration): undefined;
|
|
41
|
+
unconfigure(): undefined;
|
|
42
|
+
getConfiguration(): GPUCanvasConfigurationOut | null;
|
|
43
|
+
getCurrentTexture(): GPUTexture;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/dist/canvas.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as gfx from 'wasi:webgpu/webgpu@0.0.1';
|
|
2
|
+
import * as wasiSurface from 'wasi:surface/surface@0.0.1';
|
|
3
|
+
import * as wasiGraphicsContext from 'wasi:graphics-context/graphics-context@0.0.1';
|
|
4
|
+
import { inner, key, privateConstructorCalled, Todo, Unreachable, Unimplemented } from './common';
|
|
5
|
+
import { GPUTexture } from './webgpu';
|
|
6
|
+
export function createCanvas() {
|
|
7
|
+
return new HTMLCanvasElement(key);
|
|
8
|
+
}
|
|
9
|
+
export class HTMLCanvasElement {
|
|
10
|
+
_surface;
|
|
11
|
+
_graphicsContext;
|
|
12
|
+
#framePollable;
|
|
13
|
+
get height() {
|
|
14
|
+
return this._surface.height();
|
|
15
|
+
}
|
|
16
|
+
set height(value) {
|
|
17
|
+
this._surface.requestSetSize(value, undefined);
|
|
18
|
+
}
|
|
19
|
+
get width() {
|
|
20
|
+
return this._surface.width();
|
|
21
|
+
}
|
|
22
|
+
set width(value) {
|
|
23
|
+
this._surface.requestSetSize(undefined, value);
|
|
24
|
+
}
|
|
25
|
+
constructor(k) {
|
|
26
|
+
privateConstructorCalled(k);
|
|
27
|
+
this._surface = new wasiSurface.Surface({});
|
|
28
|
+
this._graphicsContext = new wasiGraphicsContext.Context();
|
|
29
|
+
this._surface.connectGraphicsContext(this._graphicsContext);
|
|
30
|
+
}
|
|
31
|
+
getContext(contextId, options) {
|
|
32
|
+
switch (contextId.toLowerCase()) {
|
|
33
|
+
case "2d":
|
|
34
|
+
throw new Unimplemented;
|
|
35
|
+
case "bitmaprenderer":
|
|
36
|
+
throw new Todo;
|
|
37
|
+
case "webgl":
|
|
38
|
+
throw new Unimplemented;
|
|
39
|
+
case "webgl2":
|
|
40
|
+
throw new Unimplemented;
|
|
41
|
+
case "webgpu":
|
|
42
|
+
return new GPUCanvasContext(key, this);
|
|
43
|
+
default:
|
|
44
|
+
throw new Unreachable;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
transferControlToOffscreen() {
|
|
48
|
+
throw new Todo;
|
|
49
|
+
}
|
|
50
|
+
addEventListener(type, listener, options) {
|
|
51
|
+
throw new Todo;
|
|
52
|
+
}
|
|
53
|
+
removeEventListener(type, listener, options) {
|
|
54
|
+
throw new Todo;
|
|
55
|
+
}
|
|
56
|
+
dispatchEvent(event) {
|
|
57
|
+
throw new Todo;
|
|
58
|
+
}
|
|
59
|
+
onclick = null;
|
|
60
|
+
ondblclick = null;
|
|
61
|
+
oninput = null;
|
|
62
|
+
onkeydown = null;
|
|
63
|
+
onkeyup = null;
|
|
64
|
+
onpointerdown = null;
|
|
65
|
+
onpointermove = null;
|
|
66
|
+
onpointerup = null;
|
|
67
|
+
cancelAnimationFrame(handle) {
|
|
68
|
+
throw new Todo;
|
|
69
|
+
}
|
|
70
|
+
requestAnimationFrame(callback) {
|
|
71
|
+
if (!this.#framePollable)
|
|
72
|
+
this.#framePollable = this._surface.subscribeFrame();
|
|
73
|
+
const pollable = this.#framePollable;
|
|
74
|
+
// giving the event loop a chance to do other work before blocking.
|
|
75
|
+
Promise.resolve().then(() => {
|
|
76
|
+
pollable.block();
|
|
77
|
+
this._surface.getFrame();
|
|
78
|
+
// TODO: this number should be real
|
|
79
|
+
callback(0);
|
|
80
|
+
this._graphicsContext.present();
|
|
81
|
+
});
|
|
82
|
+
// TODO: this number should be real
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export class GPUCanvasContext {
|
|
87
|
+
#canvas;
|
|
88
|
+
constructor(k, canvas) {
|
|
89
|
+
privateConstructorCalled(k);
|
|
90
|
+
this.#canvas = canvas;
|
|
91
|
+
}
|
|
92
|
+
__brand = "GPUCanvasContext";
|
|
93
|
+
get canvas() {
|
|
94
|
+
throw new Todo;
|
|
95
|
+
}
|
|
96
|
+
configure(configuration) {
|
|
97
|
+
let device = configuration.device[inner];
|
|
98
|
+
let context = this.#canvas._graphicsContext;
|
|
99
|
+
device.connectGraphicsContext(context);
|
|
100
|
+
}
|
|
101
|
+
unconfigure() {
|
|
102
|
+
throw new Todo;
|
|
103
|
+
}
|
|
104
|
+
getConfiguration() {
|
|
105
|
+
throw new Todo;
|
|
106
|
+
}
|
|
107
|
+
getCurrentTexture() {
|
|
108
|
+
const buffer = this.#canvas._graphicsContext.getCurrentBuffer();
|
|
109
|
+
let texture = gfx.GpuTexture.fromGraphicsBuffer(buffer);
|
|
110
|
+
return new GPUTexture(key, texture);
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class EventTarget {
|
|
2
|
+
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
|
3
|
+
dispatchEvent(event: Event): boolean;
|
|
4
|
+
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class Todo extends Error {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
export declare class Unimplemented extends Error {
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
12
|
+
export declare class Unreachable extends Error {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare const inner: unique symbol;
|
|
16
|
+
export declare const key: unique symbol;
|
|
17
|
+
export declare function privateConstructorCalled(k: symbol): void;
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// https://dom.spec.whatwg.org/#interface-eventtarget
|
|
2
|
+
export class EventTarget {
|
|
3
|
+
addEventListener(type, callback, options) {
|
|
4
|
+
throw new Todo;
|
|
5
|
+
}
|
|
6
|
+
dispatchEvent(event) {
|
|
7
|
+
throw new Todo;
|
|
8
|
+
}
|
|
9
|
+
removeEventListener(type, callback, options) {
|
|
10
|
+
throw new Todo;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class Todo extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("TODO: not yet implemented");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class Unimplemented extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("Unimplemented.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class Unreachable extends Error {
|
|
24
|
+
constructor() {
|
|
25
|
+
super("Unreachable code reached.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const inner = Symbol("inner");
|
|
29
|
+
export const key = Symbol("key");
|
|
30
|
+
export function privateConstructorCalled(k) {
|
|
31
|
+
if (k !== key)
|
|
32
|
+
throw new TypeError("Illegal constructor.");
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function declareGlobals(): void;
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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";
|
|
2
|
+
class Navigator {
|
|
3
|
+
gpu;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.gpu = getGpu();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function defineGlobal(name, value) {
|
|
9
|
+
Object.defineProperty(globalThis, name, {
|
|
10
|
+
value,
|
|
11
|
+
writable: true,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function declareGlobals() {
|
|
17
|
+
defineGlobal("window", globalThis);
|
|
18
|
+
defineGlobal("navigator", new Navigator());
|
|
19
|
+
defineGlobal("GPU", GPU);
|
|
20
|
+
defineGlobal("GPUAdapter", GPUAdapter);
|
|
21
|
+
// defineGlobal("GPUAdapterInfo", GPUAdapterInfo);
|
|
22
|
+
// defineGlobal("GPUSupportedLimits", GPUSupportedLimits);
|
|
23
|
+
// defineGlobal("GPUSupportedFeatures", GPUSupportedFeatures);
|
|
24
|
+
// defineGlobal("GPUDeviceLostInfo", GPUDeviceLostInfo);
|
|
25
|
+
defineGlobal("GPUDevice", GPUDevice);
|
|
26
|
+
defineGlobal("GPUQueue", GPUQueue);
|
|
27
|
+
defineGlobal("GPUBuffer", GPUBuffer);
|
|
28
|
+
defineGlobal("GPUBufferUsage", GPUBufferUsage);
|
|
29
|
+
defineGlobal("GPUMapMode", GPUMapMode);
|
|
30
|
+
defineGlobal("GPUTextureUsage", GPUTextureUsage);
|
|
31
|
+
defineGlobal("GPUTexture", GPUTexture);
|
|
32
|
+
defineGlobal("GPUTextureView", GPUTextureView);
|
|
33
|
+
defineGlobal("GPUSampler", GPUSampler);
|
|
34
|
+
defineGlobal("GPUBindGroupLayout", GPUBindGroupLayout);
|
|
35
|
+
defineGlobal("GPUPipelineLayout", GPUPipelineLayout);
|
|
36
|
+
defineGlobal("GPUBindGroup", GPUBindGroup);
|
|
37
|
+
defineGlobal("GPUShaderModule", GPUShaderModule);
|
|
38
|
+
defineGlobal("GPUShaderStage", GPUShaderStage);
|
|
39
|
+
defineGlobal("GPUComputePipeline", GPUComputePipeline);
|
|
40
|
+
defineGlobal("GPURenderPipeline", GPURenderPipeline);
|
|
41
|
+
defineGlobal("GPUColorWrite", GPUColorWrite);
|
|
42
|
+
defineGlobal("GPUCommandEncoder", GPUCommandEncoder);
|
|
43
|
+
defineGlobal("GPURenderPassEncoder", GPURenderPassEncoder);
|
|
44
|
+
defineGlobal("GPUComputePassEncoder", GPUComputePassEncoder);
|
|
45
|
+
defineGlobal("GPUCommandBuffer", GPUCommandBuffer);
|
|
46
|
+
// defineGlobal("GPURenderBundleEncoder", GPURenderBundleEncoder);
|
|
47
|
+
// defineGlobal("GPURenderBundle", GPURenderBundle);
|
|
48
|
+
defineGlobal("GPUQuerySet", GPUQuerySet);
|
|
49
|
+
// defineGlobal("GPUError", GPUError);
|
|
50
|
+
// defineGlobal("GPUValidationError", GPUValidationError);
|
|
51
|
+
// defineGlobal("GPUOutOfMemoryError", GPUOutOfMemoryError);
|
|
52
|
+
}
|
package/dist/webgpu.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import * as gfx from 'wasi:webgpu/webgpu@0.0.1';
|
|
2
|
+
import { inner } from './common';
|
|
3
|
+
export declare class GPU implements globalThis.GPU {
|
|
4
|
+
[inner]: gfx.Gpu;
|
|
5
|
+
constructor(k: symbol, i: gfx.Gpu);
|
|
6
|
+
get __brand(): 'GPU';
|
|
7
|
+
get wgslLanguageFeatures(): WGSLLanguageFeatures;
|
|
8
|
+
requestAdapter(descriptor?: GPURequestAdapterOptions): Promise<GPUAdapter | null>;
|
|
9
|
+
getPreferredCanvasFormat(): GPUTextureFormat;
|
|
10
|
+
}
|
|
11
|
+
export declare class GPUAdapter implements globalThis.GPUAdapter {
|
|
12
|
+
[inner]: gfx.GpuAdapter;
|
|
13
|
+
constructor(k: symbol, i: gfx.GpuAdapter);
|
|
14
|
+
requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
|
|
15
|
+
requestAdapterInfo(): void;
|
|
16
|
+
get __brand(): 'GPUAdapter';
|
|
17
|
+
get info(): GPUAdapterInfo;
|
|
18
|
+
get features(): GPUSupportedFeatures;
|
|
19
|
+
get limits(): GPUSupportedLimits;
|
|
20
|
+
get isFallbackAdapter(): boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class GPUSupportedFeatures implements globalThis.GPUSupportedFeatures {
|
|
23
|
+
[inner]: gfx.GpuSupportedFeatures;
|
|
24
|
+
constructor(k: symbol, i: gfx.GpuSupportedFeatures);
|
|
25
|
+
get __brand(): 'GPUSupportedFeatures';
|
|
26
|
+
get size(): number;
|
|
27
|
+
has(value: string): boolean;
|
|
28
|
+
forEach(callbackfn: (value: string, value2: string, set: ReadonlySet<string>) => void, thisArg?: any): void;
|
|
29
|
+
entries(): SetIterator<[string, string]>;
|
|
30
|
+
keys(): SetIterator<string>;
|
|
31
|
+
values(): SetIterator<string>;
|
|
32
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare class GPUSupportedLimits implements globalThis.GPUSupportedLimits {
|
|
35
|
+
[inner]: gfx.GpuSupportedLimits;
|
|
36
|
+
constructor(k: symbol, i: gfx.GpuSupportedLimits);
|
|
37
|
+
get __brand(): 'GPUSupportedLimits';
|
|
38
|
+
get maxTextureDimension1D(): number;
|
|
39
|
+
get maxTextureDimension2D(): number;
|
|
40
|
+
get maxTextureDimension3D(): number;
|
|
41
|
+
get maxTextureArrayLayers(): number;
|
|
42
|
+
get maxBindGroups(): number;
|
|
43
|
+
get maxBindGroupsPlusVertexBuffers(): number;
|
|
44
|
+
get maxBindingsPerBindGroup(): number;
|
|
45
|
+
get maxDynamicUniformBuffersPerPipelineLayout(): number;
|
|
46
|
+
get maxDynamicStorageBuffersPerPipelineLayout(): number;
|
|
47
|
+
get maxSampledTexturesPerShaderStage(): number;
|
|
48
|
+
get maxSamplersPerShaderStage(): number;
|
|
49
|
+
get maxStorageBuffersPerShaderStage(): number;
|
|
50
|
+
get maxStorageTexturesPerShaderStage(): number;
|
|
51
|
+
get maxUniformBuffersPerShaderStage(): number;
|
|
52
|
+
get maxUniformBufferBindingSize(): number;
|
|
53
|
+
get maxStorageBufferBindingSize(): number;
|
|
54
|
+
get minUniformBufferOffsetAlignment(): number;
|
|
55
|
+
get minStorageBufferOffsetAlignment(): number;
|
|
56
|
+
get maxVertexBuffers(): number;
|
|
57
|
+
get maxBufferSize(): number;
|
|
58
|
+
get maxVertexAttributes(): number;
|
|
59
|
+
get maxVertexBufferArrayStride(): number;
|
|
60
|
+
get maxInterStageShaderVariables(): number;
|
|
61
|
+
get maxColorAttachments(): number;
|
|
62
|
+
get maxColorAttachmentBytesPerSample(): number;
|
|
63
|
+
get maxComputeWorkgroupStorageSize(): number;
|
|
64
|
+
get maxComputeInvocationsPerWorkgroup(): number;
|
|
65
|
+
get maxComputeWorkgroupSizeX(): number;
|
|
66
|
+
get maxComputeWorkgroupSizeY(): number;
|
|
67
|
+
get maxComputeWorkgroupSizeZ(): number;
|
|
68
|
+
get maxComputeWorkgroupsPerDimension(): number;
|
|
69
|
+
}
|
|
70
|
+
export declare class GPUAdapterInfo implements globalThis.GPUAdapterInfo {
|
|
71
|
+
[inner]: gfx.GpuAdapterInfo;
|
|
72
|
+
constructor(k: symbol, i: gfx.GpuAdapterInfo);
|
|
73
|
+
get __brand(): 'GPUAdapterInfo';
|
|
74
|
+
get vendor(): string;
|
|
75
|
+
get architecture(): string;
|
|
76
|
+
get device(): string;
|
|
77
|
+
get description(): string;
|
|
78
|
+
}
|
|
79
|
+
export declare class GPUDevice extends EventTarget implements globalThis.GPUDevice {
|
|
80
|
+
[inner]: gfx.GpuDevice;
|
|
81
|
+
constructor(k: symbol, i: gfx.GpuDevice);
|
|
82
|
+
get __brand(): 'GPUDevice';
|
|
83
|
+
get label(): string;
|
|
84
|
+
set label(value: string);
|
|
85
|
+
get lost(): Promise<GPUDeviceLostInfo>;
|
|
86
|
+
get features(): GPUSupportedFeatures;
|
|
87
|
+
get limits(): GPUSupportedLimits;
|
|
88
|
+
get queue(): GPUQueue;
|
|
89
|
+
get adapterInfo(): GPUAdapterInfo;
|
|
90
|
+
destroy(): undefined;
|
|
91
|
+
createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer;
|
|
92
|
+
createTexture(descriptor: GPUTextureDescriptor): GPUTexture;
|
|
93
|
+
createSampler(descriptor?: GPUSamplerDescriptor): GPUSampler;
|
|
94
|
+
createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): GPUBindGroupLayout;
|
|
95
|
+
createPipelineLayout(descriptor: GPUPipelineLayoutDescriptor): GPUPipelineLayout;
|
|
96
|
+
createBindGroup(descriptor: GPUBindGroupDescriptor): GPUBindGroup;
|
|
97
|
+
createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule;
|
|
98
|
+
createComputePipeline(descriptor: GPUComputePipelineDescriptor): GPUComputePipeline;
|
|
99
|
+
createRenderPipeline(descriptor: GPURenderPipelineDescriptor): GPURenderPipeline;
|
|
100
|
+
createComputePipelineAsync(_descriptor: GPUComputePipelineDescriptor): Promise<GPUComputePipeline>;
|
|
101
|
+
createRenderPipelineAsync(descriptor: GPURenderPipelineDescriptor): Promise<GPURenderPipeline>;
|
|
102
|
+
createCommandEncoder(descriptor?: GPUCommandEncoderDescriptor): GPUCommandEncoder;
|
|
103
|
+
createRenderBundleEncoder(descriptor: GPURenderBundleEncoderDescriptor): GPURenderBundleEncoder;
|
|
104
|
+
createQuerySet(descriptor: GPUQuerySetDescriptor): GPUQuerySet;
|
|
105
|
+
pushErrorScope(filter: GPUErrorFilter): undefined;
|
|
106
|
+
popErrorScope(): Promise<GPUError | null>;
|
|
107
|
+
importExternalTexture(descriptor: GPUExternalTextureDescriptor): GPUExternalTexture;
|
|
108
|
+
onuncapturederror: ((this: globalThis.GPUDevice, ev: GPUUncapturedErrorEvent) => any) | null;
|
|
109
|
+
}
|
|
110
|
+
export declare class GPURenderBundleEncoder implements globalThis.GPURenderBundleEncoder {
|
|
111
|
+
[inner]: gfx.GpuRenderBundleEncoder;
|
|
112
|
+
constructor(k: symbol, i: gfx.GpuRenderBundleEncoder);
|
|
113
|
+
get __brand(): 'GPURenderBundleEncoder';
|
|
114
|
+
get label(): string;
|
|
115
|
+
set label(value: string);
|
|
116
|
+
finish(descriptor?: GPURenderBundleDescriptor): GPURenderBundle;
|
|
117
|
+
pushDebugGroup(groupLabel: string): undefined;
|
|
118
|
+
popDebugGroup(): undefined;
|
|
119
|
+
insertDebugMarker(markerLabel: string): undefined;
|
|
120
|
+
setBindGroup(index: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
|
|
121
|
+
setPipeline(pipeline: globalThis.GPURenderPipeline): undefined;
|
|
122
|
+
setIndexBuffer(buffer: globalThis.GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
123
|
+
setVertexBuffer(slot: GPUIndex32, buffer: globalThis.GPUBuffer | null | undefined, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
124
|
+
draw(vertexCount: GPUSize32, instanceCount?: GPUSize32, firstVertex?: GPUSize32, firstInstance?: GPUSize32): undefined;
|
|
125
|
+
drawIndexed(indexCount: GPUSize32, instanceCount?: GPUSize32, firstIndex?: GPUSize32, baseVertex?: GPUSignedOffset32, firstInstance?: GPUSize32): undefined;
|
|
126
|
+
drawIndirect(indirectBuffer: globalThis.GPUBuffer, indirectOffset: GPUSize64): undefined;
|
|
127
|
+
drawIndexedIndirect(indirectBuffer: globalThis.GPUBuffer, indirectOffset: GPUSize64): undefined;
|
|
128
|
+
}
|
|
129
|
+
export declare class GPURenderBundle implements globalThis.GPURenderBundle {
|
|
130
|
+
[inner]: gfx.GpuRenderBundle;
|
|
131
|
+
constructor(k: symbol, i: gfx.GpuRenderBundle);
|
|
132
|
+
get __brand(): 'GPURenderBundle';
|
|
133
|
+
get label(): string;
|
|
134
|
+
set label(value: string);
|
|
135
|
+
}
|
|
136
|
+
export declare class GPUShaderModule implements globalThis.GPUShaderModule {
|
|
137
|
+
[inner]: gfx.GpuShaderModule;
|
|
138
|
+
constructor(k: symbol, i: gfx.GpuShaderModule);
|
|
139
|
+
get __brand(): 'GPUShaderModule';
|
|
140
|
+
get label(): string;
|
|
141
|
+
set label(value: string);
|
|
142
|
+
getCompilationInfo(): Promise<GPUCompilationInfo>;
|
|
143
|
+
}
|
|
144
|
+
export declare class GPUComputePipeline implements globalThis.GPUComputePipeline {
|
|
145
|
+
[inner]: gfx.GpuComputePipeline;
|
|
146
|
+
constructor(k: symbol, i: gfx.GpuComputePipeline);
|
|
147
|
+
get __brand(): 'GPUComputePipeline';
|
|
148
|
+
get label(): string;
|
|
149
|
+
set label(value: string);
|
|
150
|
+
getBindGroupLayout(index: number): GPUBindGroupLayout;
|
|
151
|
+
}
|
|
152
|
+
export declare class GPUPipelineLayout implements globalThis.GPUPipelineLayout {
|
|
153
|
+
[inner]: gfx.GpuPipelineLayout;
|
|
154
|
+
constructor(k: symbol, i: gfx.GpuPipelineLayout);
|
|
155
|
+
get __brand(): 'GPUPipelineLayout';
|
|
156
|
+
get label(): string;
|
|
157
|
+
set label(value: string);
|
|
158
|
+
}
|
|
159
|
+
export declare class GPURenderPipeline implements globalThis.GPURenderPipeline {
|
|
160
|
+
[inner]: gfx.GpuRenderPipeline;
|
|
161
|
+
constructor(k: symbol, i: gfx.GpuRenderPipeline);
|
|
162
|
+
get __brand(): 'GPURenderPipeline';
|
|
163
|
+
get label(): string;
|
|
164
|
+
set label(value: string);
|
|
165
|
+
getBindGroupLayout(index: number): GPUBindGroupLayout;
|
|
166
|
+
}
|
|
167
|
+
export declare class GPUBuffer implements globalThis.GPUBuffer {
|
|
168
|
+
[inner]: gfx.GpuBuffer;
|
|
169
|
+
_mappedRangeBuffer: Uint8Array<ArrayBuffer> | undefined;
|
|
170
|
+
_mappedRangeOffset: bigint | undefined;
|
|
171
|
+
_mappedRangeSize: bigint | undefined;
|
|
172
|
+
constructor(k: symbol, i: gfx.GpuBuffer);
|
|
173
|
+
get __brand(): 'GPUBuffer';
|
|
174
|
+
get label(): string;
|
|
175
|
+
set label(value: string);
|
|
176
|
+
get size(): GPUSize64Out;
|
|
177
|
+
get usage(): GPUFlagsConstant;
|
|
178
|
+
get mapState(): GPUBufferMapState;
|
|
179
|
+
mapAsync(mode: GPUMapModeFlags, offset?: GPUSize64, size?: GPUSize64): Promise<undefined>;
|
|
180
|
+
getMappedRange(offset?: GPUSize64, size?: GPUSize64): ArrayBuffer;
|
|
181
|
+
unmap(): undefined;
|
|
182
|
+
destroy(): undefined;
|
|
183
|
+
}
|
|
184
|
+
export declare class GPUQueue implements globalThis.GPUQueue {
|
|
185
|
+
[inner]: gfx.GpuQueue;
|
|
186
|
+
constructor(k: symbol, i: gfx.GpuQueue);
|
|
187
|
+
get __brand(): 'GPUQueue';
|
|
188
|
+
get label(): string;
|
|
189
|
+
set label(value: string);
|
|
190
|
+
submit(commandBuffers: Iterable<GPUCommandBuffer>): undefined;
|
|
191
|
+
onSubmittedWorkDone(): Promise<undefined>;
|
|
192
|
+
writeBuffer(buffer: GPUBuffer, bufferOffset: GPUSize64, data: BufferSource | SharedArrayBuffer, dataOffset?: GPUSize64, size?: GPUSize64): undefined;
|
|
193
|
+
writeTexture(destination: GPUTexelCopyTextureInfo, data: BufferSource | SharedArrayBuffer, dataLayout: GPUTexelCopyBufferLayout, size: GPUExtent3D): undefined;
|
|
194
|
+
copyExternalImageToTexture(source: GPUCopyExternalImageSourceInfo, destination: GPUCopyExternalImageDestInfo, copySize: GPUExtent3D): undefined;
|
|
195
|
+
}
|
|
196
|
+
export declare class GPUBindGroupLayout implements globalThis.GPUBindGroupLayout {
|
|
197
|
+
[inner]: gfx.GpuBindGroupLayout;
|
|
198
|
+
constructor(k: symbol, i: gfx.GpuBindGroupLayout);
|
|
199
|
+
get __brand(): 'GPUBindGroupLayout';
|
|
200
|
+
get label(): string;
|
|
201
|
+
set label(value: string);
|
|
202
|
+
}
|
|
203
|
+
export declare class GPUBindGroup implements globalThis.GPUBindGroup {
|
|
204
|
+
[inner]: gfx.GpuBindGroup;
|
|
205
|
+
constructor(k: symbol, i: gfx.GpuBindGroup);
|
|
206
|
+
get __brand(): 'GPUBindGroup';
|
|
207
|
+
get label(): string;
|
|
208
|
+
set label(value: string);
|
|
209
|
+
}
|
|
210
|
+
export declare class GPUSampler implements globalThis.GPUSampler {
|
|
211
|
+
[inner]: gfx.GpuSampler;
|
|
212
|
+
constructor(k: symbol, i: gfx.GpuSampler);
|
|
213
|
+
get __brand(): 'GPUSampler';
|
|
214
|
+
get label(): string;
|
|
215
|
+
set label(value: string);
|
|
216
|
+
}
|
|
217
|
+
export declare class GPUTextureView implements globalThis.GPUTextureView {
|
|
218
|
+
[inner]: gfx.GpuTextureView;
|
|
219
|
+
constructor(k: symbol, i: gfx.GpuTextureView);
|
|
220
|
+
get __brand(): 'GPUTextureView';
|
|
221
|
+
get label(): string;
|
|
222
|
+
set label(value: string);
|
|
223
|
+
}
|
|
224
|
+
export declare class GPUTexture implements globalThis.GPUTexture {
|
|
225
|
+
[inner]: gfx.GpuTexture;
|
|
226
|
+
constructor(k: symbol, i: gfx.GpuTexture);
|
|
227
|
+
get __brand(): 'GPUTexture';
|
|
228
|
+
get label(): string;
|
|
229
|
+
set label(value: string);
|
|
230
|
+
get width(): number;
|
|
231
|
+
get height(): number;
|
|
232
|
+
get depthOrArrayLayers(): number;
|
|
233
|
+
get mipLevelCount(): number;
|
|
234
|
+
get sampleCount(): number;
|
|
235
|
+
get dimension(): GPUTextureDimension;
|
|
236
|
+
get format(): GPUTextureFormat;
|
|
237
|
+
get usage(): number;
|
|
238
|
+
createView(descriptor?: GPUTextureViewDescriptor): globalThis.GPUTextureView;
|
|
239
|
+
destroy(): undefined;
|
|
240
|
+
}
|
|
241
|
+
export declare class GPUCommandEncoder implements globalThis.GPUCommandEncoder {
|
|
242
|
+
[inner]: gfx.GpuCommandEncoder;
|
|
243
|
+
constructor(k: symbol, i: gfx.GpuCommandEncoder);
|
|
244
|
+
get __brand(): 'GPUCommandEncoder';
|
|
245
|
+
get label(): string;
|
|
246
|
+
set label(value: string);
|
|
247
|
+
beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder;
|
|
248
|
+
beginComputePass(descriptor?: GPUComputePassDescriptor): GPUComputePassEncoder;
|
|
249
|
+
copyBufferToBuffer(source: GPUBuffer, sourceOffset: GPUSize64, destination: GPUBuffer, destinationOffset: GPUSize64, size: GPUSize64): undefined;
|
|
250
|
+
copyBufferToTexture(source: GPUTexelCopyBufferInfo, destination: GPUTexelCopyTextureInfo, copySize: GPUExtent3D): undefined;
|
|
251
|
+
copyTextureToBuffer(source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyBufferInfo, copySize: GPUExtent3D): undefined;
|
|
252
|
+
copyTextureToTexture(source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyTextureInfo, copySize: GPUExtent3D): undefined;
|
|
253
|
+
clearBuffer(buffer: GPUBuffer, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
254
|
+
resolveQuerySet(querySet: GPUQuerySet, firstQuery: GPUSize32, queryCount: GPUSize32, destination: globalThis.GPUBuffer, destinationOffset: GPUSize64): undefined;
|
|
255
|
+
finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer;
|
|
256
|
+
pushDebugGroup(groupLabel: string): undefined;
|
|
257
|
+
popDebugGroup(): undefined;
|
|
258
|
+
insertDebugMarker(markerLabel: string): undefined;
|
|
259
|
+
}
|
|
260
|
+
export declare class GPUComputePassEncoder implements globalThis.GPUComputePassEncoder {
|
|
261
|
+
[inner]: gfx.GpuComputePassEncoder;
|
|
262
|
+
constructor(k: symbol, i: gfx.GpuComputePassEncoder);
|
|
263
|
+
get __brand(): 'GPUComputePassEncoder';
|
|
264
|
+
get label(): string;
|
|
265
|
+
set label(value: string);
|
|
266
|
+
setPipeline(pipeline: GPUComputePipeline): undefined;
|
|
267
|
+
dispatchWorkgroups(workgroupCountX: GPUSize32, workgroupCountY?: GPUSize32, workgroupCountZ?: GPUSize32): undefined;
|
|
268
|
+
dispatchWorkgroupsIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
|
|
269
|
+
end(): undefined;
|
|
270
|
+
pushDebugGroup(groupLabel: string): undefined;
|
|
271
|
+
popDebugGroup(): undefined;
|
|
272
|
+
insertDebugMarker(markerLabel: string): undefined;
|
|
273
|
+
setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null, dynamicOffsetsData?: Iterable<GPUBufferDynamicOffset> | Uint32Array, dynamicOffsetsDataStart?: GPUSize64, dynamicOffsetsDataLength?: GPUSize32): undefined;
|
|
274
|
+
}
|
|
275
|
+
export declare class GPURenderPassEncoder implements globalThis.GPURenderPassEncoder {
|
|
276
|
+
[inner]: gfx.GpuRenderPassEncoder;
|
|
277
|
+
constructor(k: symbol, i: gfx.GpuRenderPassEncoder);
|
|
278
|
+
get __brand(): 'GPURenderPassEncoder';
|
|
279
|
+
get label(): string;
|
|
280
|
+
set label(value: string);
|
|
281
|
+
setViewport(x: number, y: number, width: number, height: number, minDepth: number, maxDepth: number): undefined;
|
|
282
|
+
setScissorRect(x: GPUIntegerCoordinate, y: GPUIntegerCoordinate, width: GPUIntegerCoordinate, height: GPUIntegerCoordinate): undefined;
|
|
283
|
+
setBlendConstant(color: GPUColor): undefined;
|
|
284
|
+
setStencilReference(reference: GPUStencilValue): undefined;
|
|
285
|
+
beginOcclusionQuery(queryIndex: GPUSize32): undefined;
|
|
286
|
+
endOcclusionQuery(): undefined;
|
|
287
|
+
executeBundles(bundles: Iterable<GPURenderBundle>): undefined;
|
|
288
|
+
end(): undefined;
|
|
289
|
+
pushDebugGroup(groupLabel: string): undefined;
|
|
290
|
+
popDebugGroup(): undefined;
|
|
291
|
+
insertDebugMarker(markerLabel: string): undefined;
|
|
292
|
+
setBindGroup(index: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
|
|
293
|
+
setPipeline(pipeline: GPURenderPipeline): undefined;
|
|
294
|
+
setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
295
|
+
setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer | null, offset?: GPUSize64, size?: GPUSize64): undefined;
|
|
296
|
+
draw(vertexCount: GPUSize32, instanceCount?: GPUSize32, firstVertex?: GPUSize32, firstInstance?: GPUSize32): undefined;
|
|
297
|
+
drawIndexed(indexCount: GPUSize32, instanceCount?: GPUSize32, firstIndex?: GPUSize32, baseVertex?: GPUSignedOffset32, firstInstance?: GPUSize32): undefined;
|
|
298
|
+
drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
|
|
299
|
+
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
|
|
300
|
+
}
|
|
301
|
+
export declare class GPUQuerySet implements globalThis.GPUQuerySet {
|
|
302
|
+
[inner]: gfx.GpuQuerySet;
|
|
303
|
+
constructor(k: symbol, i: gfx.GpuQuerySet);
|
|
304
|
+
destroy(): undefined;
|
|
305
|
+
get __brand(): 'GPUQuerySet';
|
|
306
|
+
get label(): string;
|
|
307
|
+
set label(value: string);
|
|
308
|
+
get type(): GPUQueryType;
|
|
309
|
+
get count(): number;
|
|
310
|
+
}
|
|
311
|
+
export declare class GPUCommandBuffer implements globalThis.GPUCommandBuffer {
|
|
312
|
+
[inner]: gfx.GpuCommandBuffer;
|
|
313
|
+
constructor(k: symbol, i: gfx.GpuCommandBuffer);
|
|
314
|
+
get __brand(): 'GPUCommandBuffer';
|
|
315
|
+
get label(): string;
|
|
316
|
+
set label(value: string);
|
|
317
|
+
}
|
|
318
|
+
export declare function getGpu(): GPU;
|
|
319
|
+
export declare const GPUBufferUsage: {
|
|
320
|
+
MAP_READ: number;
|
|
321
|
+
MAP_WRITE: number;
|
|
322
|
+
COPY_SRC: number;
|
|
323
|
+
COPY_DST: number;
|
|
324
|
+
INDEX: number;
|
|
325
|
+
VERTEX: number;
|
|
326
|
+
UNIFORM: number;
|
|
327
|
+
STORAGE: number;
|
|
328
|
+
INDIRECT: number;
|
|
329
|
+
QUERY_RESOLVE: number;
|
|
330
|
+
};
|
|
331
|
+
export declare const GPUMapMode: {
|
|
332
|
+
READ: number;
|
|
333
|
+
WRITE: number;
|
|
334
|
+
};
|
|
335
|
+
export declare const GPUTextureUsage: {
|
|
336
|
+
COPY_SRC: number;
|
|
337
|
+
COPY_DST: number;
|
|
338
|
+
TEXTURE_BINDING: number;
|
|
339
|
+
STORAGE_BINDING: number;
|
|
340
|
+
RENDER_ATTACHMENT: number;
|
|
341
|
+
};
|
|
342
|
+
export declare const GPUShaderStage: {
|
|
343
|
+
VERTEX: number;
|
|
344
|
+
FRAGMENT: number;
|
|
345
|
+
COMPUTE: number;
|
|
346
|
+
};
|
|
347
|
+
export declare const GPUColorWrite: {
|
|
348
|
+
RED: number;
|
|
349
|
+
GREEN: number;
|
|
350
|
+
BLUE: number;
|
|
351
|
+
ALPHA: number;
|
|
352
|
+
ALL: number;
|
|
353
|
+
};
|
|
@@ -1,42 +1,5 @@
|
|
|
1
1
|
import * as gfx from 'wasi:webgpu/webgpu@0.0.1';
|
|
2
|
-
import
|
|
3
|
-
import * as wasiGraphicsContext from 'wasi:graphics-context/graphics-context@0.0.1';
|
|
4
|
-
export function createCanvas() {
|
|
5
|
-
return new HTMLCanvasElement(key);
|
|
6
|
-
}
|
|
7
|
-
// https://dom.spec.whatwg.org/#interface-eventtarget
|
|
8
|
-
class EventTarget {
|
|
9
|
-
addEventListener(type, callback, options) {
|
|
10
|
-
throw new Todo;
|
|
11
|
-
}
|
|
12
|
-
dispatchEvent(event) {
|
|
13
|
-
throw new Todo;
|
|
14
|
-
}
|
|
15
|
-
removeEventListener(type, callback, options) {
|
|
16
|
-
throw new Todo;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
class Todo extends Error {
|
|
20
|
-
constructor() {
|
|
21
|
-
super("TODO: not yet implemented");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
class Unimplemented extends Error {
|
|
25
|
-
constructor() {
|
|
26
|
-
super("Unimplemented.");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class Unreachable extends Error {
|
|
30
|
-
constructor() {
|
|
31
|
-
super("Unreachable code reached.");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const inner = Symbol("inner");
|
|
35
|
-
const key = Symbol("key");
|
|
36
|
-
function privateConstructorCalled(k) {
|
|
37
|
-
if (k !== key)
|
|
38
|
-
throw new TypeError("Illegal constructor.");
|
|
39
|
-
}
|
|
2
|
+
import { inner, key, privateConstructorCalled, Todo, Unreachable } from './common';
|
|
40
3
|
// converters
|
|
41
4
|
// don't use raw `Number(x)`/`BigInt(x)` because they accept non-numeric values
|
|
42
5
|
function numToBigInt(n) {
|
|
@@ -396,110 +359,7 @@ function convertBufferToUint8Array(buffer) {
|
|
|
396
359
|
throw new Unreachable;
|
|
397
360
|
}
|
|
398
361
|
}
|
|
399
|
-
|
|
400
|
-
_surface;
|
|
401
|
-
_graphicsContext;
|
|
402
|
-
#framePollable;
|
|
403
|
-
get height() {
|
|
404
|
-
return this._surface.height();
|
|
405
|
-
}
|
|
406
|
-
set height(value) {
|
|
407
|
-
this._surface.requestSetSize(value, undefined);
|
|
408
|
-
}
|
|
409
|
-
get width() {
|
|
410
|
-
return this._surface.width();
|
|
411
|
-
}
|
|
412
|
-
set width(value) {
|
|
413
|
-
this._surface.requestSetSize(undefined, value);
|
|
414
|
-
}
|
|
415
|
-
constructor(k) {
|
|
416
|
-
privateConstructorCalled(k);
|
|
417
|
-
this._surface = new wasiSurface.Surface({});
|
|
418
|
-
this._graphicsContext = new wasiGraphicsContext.Context();
|
|
419
|
-
this._surface.connectGraphicsContext(this._graphicsContext);
|
|
420
|
-
}
|
|
421
|
-
getContext(contextId, options) {
|
|
422
|
-
switch (contextId.toLowerCase()) {
|
|
423
|
-
case "2d":
|
|
424
|
-
throw new Unimplemented;
|
|
425
|
-
case "bitmaprenderer":
|
|
426
|
-
throw new Todo;
|
|
427
|
-
case "webgl":
|
|
428
|
-
throw new Unimplemented;
|
|
429
|
-
case "webgl2":
|
|
430
|
-
throw new Unimplemented;
|
|
431
|
-
case "webgpu":
|
|
432
|
-
return new GPUCanvasContext(key, this);
|
|
433
|
-
default:
|
|
434
|
-
throw new Unreachable;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
transferControlToOffscreen() {
|
|
438
|
-
throw new Todo;
|
|
439
|
-
}
|
|
440
|
-
addEventListener(type, listener, options) {
|
|
441
|
-
throw new Todo;
|
|
442
|
-
}
|
|
443
|
-
removeEventListener(type, listener, options) {
|
|
444
|
-
throw new Todo;
|
|
445
|
-
}
|
|
446
|
-
dispatchEvent(event) {
|
|
447
|
-
throw new Todo;
|
|
448
|
-
}
|
|
449
|
-
onclick = null;
|
|
450
|
-
ondblclick = null;
|
|
451
|
-
oninput = null;
|
|
452
|
-
onkeydown = null;
|
|
453
|
-
onkeyup = null;
|
|
454
|
-
onpointerdown = null;
|
|
455
|
-
onpointermove = null;
|
|
456
|
-
onpointerup = null;
|
|
457
|
-
cancelAnimationFrame(handle) {
|
|
458
|
-
throw new Todo;
|
|
459
|
-
}
|
|
460
|
-
requestAnimationFrame(callback) {
|
|
461
|
-
if (!this.#framePollable)
|
|
462
|
-
this.#framePollable = this._surface.subscribeFrame();
|
|
463
|
-
const pollable = this.#framePollable;
|
|
464
|
-
// giving the event loop a chance to do other work before blocking.
|
|
465
|
-
Promise.resolve().then(() => {
|
|
466
|
-
pollable.block();
|
|
467
|
-
this._surface.getFrame();
|
|
468
|
-
// TODO: this number should be real
|
|
469
|
-
callback(0);
|
|
470
|
-
this._graphicsContext.present();
|
|
471
|
-
});
|
|
472
|
-
// TODO: this number should be real
|
|
473
|
-
return 0;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
export class GPUCanvasContext {
|
|
477
|
-
#canvas;
|
|
478
|
-
constructor(k, canvas) {
|
|
479
|
-
privateConstructorCalled(k);
|
|
480
|
-
this.#canvas = canvas;
|
|
481
|
-
}
|
|
482
|
-
__brand = "GPUCanvasContext";
|
|
483
|
-
get canvas() {
|
|
484
|
-
throw new Todo;
|
|
485
|
-
}
|
|
486
|
-
configure(configuration) {
|
|
487
|
-
let device = configuration.device[inner];
|
|
488
|
-
let context = this.#canvas._graphicsContext;
|
|
489
|
-
device.connectGraphicsContext(context);
|
|
490
|
-
}
|
|
491
|
-
unconfigure() {
|
|
492
|
-
throw new Todo;
|
|
493
|
-
}
|
|
494
|
-
getConfiguration() {
|
|
495
|
-
throw new Todo;
|
|
496
|
-
}
|
|
497
|
-
getCurrentTexture() {
|
|
498
|
-
const buffer = this.#canvas._graphicsContext.getCurrentBuffer();
|
|
499
|
-
let texture = gfx.GpuTexture.fromGraphicsBuffer(buffer);
|
|
500
|
-
return new GPUTexture(key, texture);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
362
|
+
// 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.
|
|
503
363
|
export class GPU {
|
|
504
364
|
[inner];
|
|
505
365
|
constructor(k, i) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wasi-gfx/js-webgpu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "WebGPU JavaScript API on top of wasi-gfx",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
"./canvas": {
|
|
7
|
+
"types": "./dist/canvas.d.ts",
|
|
8
|
+
"default": "./dist/canvas.js"
|
|
9
|
+
},
|
|
10
|
+
"./webgpu": {
|
|
11
|
+
"types": "./dist/webgpu.d.ts",
|
|
12
|
+
"default": "./dist/webgpu.js"
|
|
13
|
+
},
|
|
14
|
+
"./globals": {
|
|
15
|
+
"types": "./dist/globals.d.ts",
|
|
16
|
+
"default": "./dist/globals.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
6
19
|
"files": [
|
|
7
20
|
"dist/",
|
|
8
21
|
"wit/",
|