@vgpu/core 0.0.1
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/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/app-types.d.ts +13 -0
- package/dist/app-types.d.ts.map +1 -0
- package/dist/app-types.js +2 -0
- package/dist/app-types.js.map +1 -0
- package/dist/app.d.ts +5 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +7 -0
- package/dist/app.js.map +1 -0
- package/dist/buffer.d.ts +15 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +35 -0
- package/dist/buffer.js.map +1 -0
- package/dist/device.d.ts +26 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +84 -0
- package/dist/device.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/gpuConstants.d.ts +5 -0
- package/dist/gpuConstants.d.ts.map +1 -0
- package/dist/gpuConstants.js +41 -0
- package/dist/gpuConstants.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mock-gpu-storage.d.ts +9 -0
- package/dist/mock-gpu-storage.d.ts.map +1 -0
- package/dist/mock-gpu-storage.js +7 -0
- package/dist/mock-gpu-storage.js.map +1 -0
- package/dist/mockGpu.d.ts +3 -0
- package/dist/mockGpu.d.ts.map +1 -0
- package/dist/mockGpu.js +82 -0
- package/dist/mockGpu.js.map +1 -0
- package/dist/queue.d.ts +8 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +13 -0
- package/dist/queue.js.map +1 -0
- package/dist/readback.d.ts +8 -0
- package/dist/readback.d.ts.map +1 -0
- package/dist/readback.js +62 -0
- package/dist/readback.js.map +1 -0
- package/dist/shader.d.ts +14 -0
- package/dist/shader.d.ts.map +1 -0
- package/dist/shader.js +25 -0
- package/dist/shader.js.map +1 -0
- package/dist/texture.d.ts +24 -0
- package/dist/texture.d.ts.map +1 -0
- package/dist/texture.js +53 -0
- package/dist/texture.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
- package/src/App.docs.md +5 -0
- package/src/Buffer.docs.md +6 -0
- package/src/Device.docs.md +6 -0
- package/src/Queue.docs.md +5 -0
- package/src/Shader.docs.md +25 -0
- package/src/Texture.docs.md +28 -0
- package/src/VGPUAdapter.docs.md +5 -0
- package/src/VGPUError.docs.md +5 -0
- package/src/createMockGPUDevice.docs.md +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vercel, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @vgpu/core
|
|
2
|
+
|
|
3
|
+
> 0.0.1 — early preview
|
|
4
|
+
|
|
5
|
+
`@vgpu/core` is the runtime foundation for vgpu. It gives you a small wrapper layer around WebGPU devices, queues, buffers, textures, and shader modules, plus an `App.create()` entry point that asks an adapter for a device and returns a compact app instance. In 0.0.1 the goal is portability and a minimal public surface, not a fully opinionated engine.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @vgpu/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Exports
|
|
14
|
+
|
|
15
|
+
### Classes
|
|
16
|
+
- `App`
|
|
17
|
+
- `Buffer`
|
|
18
|
+
- `Device`
|
|
19
|
+
- `Queue`
|
|
20
|
+
- `Shader`
|
|
21
|
+
- `Texture`
|
|
22
|
+
- `VGPUError`
|
|
23
|
+
- `ValidationError`
|
|
24
|
+
|
|
25
|
+
### Functions
|
|
26
|
+
- `createMockGPUDevice`
|
|
27
|
+
|
|
28
|
+
### Types
|
|
29
|
+
- `AppCreateOptions`
|
|
30
|
+
- `AppInstance`
|
|
31
|
+
- `VGPUAdapter`
|
|
32
|
+
- `BufferOptions`
|
|
33
|
+
- `BufferUsageName`
|
|
34
|
+
- `BufferWriteData`
|
|
35
|
+
- `TextureOptions`
|
|
36
|
+
- `TextureUsageName`
|
|
37
|
+
- `CreateDeviceOptions`
|
|
38
|
+
- `ShaderInput`
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { App } from "@vgpu/core";
|
|
44
|
+
import { createMockAdapter } from "@vgpu/adapter-mock";
|
|
45
|
+
|
|
46
|
+
const { device } = await App.create({ adapter: createMockAdapter() });
|
|
47
|
+
const data = new Float32Array([1, 2, 3, 4]);
|
|
48
|
+
const buffer = device.createBuffer({
|
|
49
|
+
size: data.byteLength,
|
|
50
|
+
usage: ["copy_dst", "copy_src", "storage"],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
buffer.write(data);
|
|
54
|
+
const copy = new Float32Array(await buffer.read(data.byteLength));
|
|
55
|
+
device.destroy();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Device } from "./device.ts";
|
|
2
|
+
import type { CreateDeviceOptions } from "./types.ts";
|
|
3
|
+
export interface AppCreateOptions extends CreateDeviceOptions {
|
|
4
|
+
readonly adapter: VGPUAdapter;
|
|
5
|
+
}
|
|
6
|
+
export interface AppInstance {
|
|
7
|
+
readonly device: Device;
|
|
8
|
+
readonly queue: Device["queue"];
|
|
9
|
+
}
|
|
10
|
+
export interface VGPUAdapter {
|
|
11
|
+
requestDevice(opts?: CreateDeviceOptions): Promise<Device>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=app-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-types.d.ts","sourceRoot":"","sources":["../src/app-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAC3D,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-types.js","sourceRoot":"","sources":["../src/app-types.ts"],"names":[],"mappings":""}
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEpE,qBAAa,GAAG;WACD,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CAIlE"}
|
package/dist/app.js
ADDED
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG;IACd,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAsB;QACxC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC;CACF"}
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Device } from "./device.ts";
|
|
2
|
+
import type { BufferOptions, BufferWriteData } from "./types.ts";
|
|
3
|
+
export declare class Buffer {
|
|
4
|
+
private readonly device;
|
|
5
|
+
readonly gpu: GPUBuffer;
|
|
6
|
+
readonly options: BufferOptions;
|
|
7
|
+
private destroyed;
|
|
8
|
+
constructor(device: Device, gpu: GPUBuffer, options: BufferOptions);
|
|
9
|
+
write(data: BufferWriteData, offset?: number): void;
|
|
10
|
+
read(byteLength: number, offset?: number): Promise<ArrayBuffer>;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
private assertAlive;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEjE,qBAAa,MAAM;IAIf,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,QAAQ,CAAC,GAAG,EAAE,SAAS;IACvB,QAAQ,CAAC,OAAO,EAAE,aAAa;IALjC,OAAO,CAAC,SAAS,CAAS;gBAGP,MAAM,EAAE,MAAM,EACtB,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,aAAa;IAGjC,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,SAAI,GAAG,IAAI;IAKxC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IAKhE,OAAO,IAAI,IAAI;IAMf,OAAO,IAAI,IAAI;IAIf,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/buffer.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isMockGPUBuffer } from "./mock-gpu-storage.js";
|
|
2
|
+
export class Buffer {
|
|
3
|
+
device;
|
|
4
|
+
gpu;
|
|
5
|
+
options;
|
|
6
|
+
destroyed = false;
|
|
7
|
+
constructor(device, gpu, options) {
|
|
8
|
+
this.device = device;
|
|
9
|
+
this.gpu = gpu;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
write(data, offset = 0) {
|
|
13
|
+
this.assertAlive();
|
|
14
|
+
this.device.queue.writeBuffer(this.gpu, offset, data);
|
|
15
|
+
}
|
|
16
|
+
async read(byteLength, offset = 0) {
|
|
17
|
+
this.assertAlive();
|
|
18
|
+
return this.device.readback.read(this.gpu, byteLength, offset);
|
|
19
|
+
}
|
|
20
|
+
destroy() {
|
|
21
|
+
if (this.destroyed)
|
|
22
|
+
return;
|
|
23
|
+
this.destroyed = true;
|
|
24
|
+
if (!isMockGPUBuffer(this.gpu))
|
|
25
|
+
this.gpu.destroy();
|
|
26
|
+
}
|
|
27
|
+
dispose() {
|
|
28
|
+
this.destroy();
|
|
29
|
+
}
|
|
30
|
+
assertAlive() {
|
|
31
|
+
if (this.destroyed)
|
|
32
|
+
throw new Error("Buffer is destroyed");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,MAAM,OAAO,MAAM;IAIE;IACR;IACA;IALH,SAAS,GAAG,KAAK,CAAC;IAE1B,YACmB,MAAc,EACtB,GAAc,EACd,OAAsB;QAFd,WAAM,GAAN,MAAM,CAAQ;QACtB,QAAG,GAAH,GAAG,CAAW;QACd,YAAO,GAAP,OAAO,CAAe;IAC9B,CAAC;IAEJ,KAAK,CAAC,IAAqB,EAAE,MAAM,GAAG,CAAC;QACrC,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAkB,EAAE,MAAM,GAAG,CAAC;QACvC,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAEO,WAAW;QACjB,IAAI,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
package/dist/device.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Buffer } from "./buffer.ts";
|
|
2
|
+
import { Queue } from "./queue.ts";
|
|
3
|
+
import { Shader, type ShaderInput } from "./shader.ts";
|
|
4
|
+
import { Texture } from "./texture.ts";
|
|
5
|
+
import { Readback } from "./readback.ts";
|
|
6
|
+
import { type VGPUError } from "./errors.ts";
|
|
7
|
+
import type { BufferOptions, TextureOptions } from "./types.ts";
|
|
8
|
+
export declare class Device {
|
|
9
|
+
readonly gpu: GPUDevice;
|
|
10
|
+
readonly adapterInfo: GPUAdapterInfo | null;
|
|
11
|
+
readonly queue: Queue;
|
|
12
|
+
/** @internal — use Buffer.read() and Texture.read() instead */
|
|
13
|
+
readonly readback: Readback;
|
|
14
|
+
private readonly scopes;
|
|
15
|
+
private destroyed;
|
|
16
|
+
constructor(gpu: GPUDevice, adapterInfo?: GPUAdapterInfo | null);
|
|
17
|
+
createShader(input: ShaderInput): Shader;
|
|
18
|
+
createTexture(opts: TextureOptions): Texture;
|
|
19
|
+
createBuffer(opts: BufferOptions): Buffer;
|
|
20
|
+
pushErrorScope(filter: GPUErrorFilter): void;
|
|
21
|
+
popErrorScope(): Promise<VGPUError | null>;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
private captureError;
|
|
25
|
+
}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,0 +1,84 @@
|
|
|
1
|
+
import { compile } from "@vgpu/wgsl";
|
|
2
|
+
import { Buffer } from "./buffer.js";
|
|
3
|
+
import { bufferUsageFlags } from "./gpuConstants.js";
|
|
4
|
+
import { mockBufferDescriptor } from "./mockGpu.js";
|
|
5
|
+
import { Queue } from "./queue.js";
|
|
6
|
+
import { Shader } from "./shader.js";
|
|
7
|
+
import { Texture, toGPUTextureDescriptor } from "./texture.js";
|
|
8
|
+
import { Readback } from "./readback.js";
|
|
9
|
+
import { ValidationError } from "./errors.js";
|
|
10
|
+
export class Device {
|
|
11
|
+
gpu;
|
|
12
|
+
adapterInfo;
|
|
13
|
+
queue;
|
|
14
|
+
/** @internal — use Buffer.read() and Texture.read() instead */
|
|
15
|
+
readback;
|
|
16
|
+
scopes = [];
|
|
17
|
+
destroyed = false;
|
|
18
|
+
constructor(gpu, adapterInfo = null) {
|
|
19
|
+
this.gpu = gpu;
|
|
20
|
+
this.adapterInfo = adapterInfo;
|
|
21
|
+
this.queue = new Queue(gpu.queue);
|
|
22
|
+
this.readback = new Readback(gpu);
|
|
23
|
+
}
|
|
24
|
+
createShader(input) {
|
|
25
|
+
const resolved = typeof input === "string" ? compile(input) : input;
|
|
26
|
+
return new Shader(this.gpu.createShaderModule({ code: resolved.wgsl }), resolved);
|
|
27
|
+
}
|
|
28
|
+
createTexture(opts) {
|
|
29
|
+
return new Texture(this, this.gpu.createTexture(toGPUTextureDescriptor(opts)), opts);
|
|
30
|
+
}
|
|
31
|
+
createBuffer(opts) {
|
|
32
|
+
const error = validateBufferOptions(opts);
|
|
33
|
+
if (error)
|
|
34
|
+
this.captureError(error);
|
|
35
|
+
const desc = error ? mockBufferDescriptor(Math.max(4, opts.size || 4)) : toGPUBufferDescriptor(opts);
|
|
36
|
+
return new Buffer(this, this.gpu.createBuffer(desc), opts);
|
|
37
|
+
}
|
|
38
|
+
pushErrorScope(filter) {
|
|
39
|
+
this.scopes.push([]);
|
|
40
|
+
this.gpu.pushErrorScope?.(filter);
|
|
41
|
+
}
|
|
42
|
+
async popErrorScope() {
|
|
43
|
+
const scope = this.scopes.pop();
|
|
44
|
+
const nativeError = await this.gpu.popErrorScope?.();
|
|
45
|
+
return scope?.[0] ?? nativeErrorToVGPUError(nativeError) ?? null;
|
|
46
|
+
}
|
|
47
|
+
destroy() {
|
|
48
|
+
if (this.destroyed)
|
|
49
|
+
return;
|
|
50
|
+
this.destroyed = true;
|
|
51
|
+
this.readback.destroy();
|
|
52
|
+
this.gpu.destroy();
|
|
53
|
+
}
|
|
54
|
+
dispose() {
|
|
55
|
+
this.destroy();
|
|
56
|
+
}
|
|
57
|
+
captureError(error) {
|
|
58
|
+
const scope = this.scopes.at(-1);
|
|
59
|
+
if (scope)
|
|
60
|
+
scope.push(error);
|
|
61
|
+
else
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function validateBufferOptions(opts) {
|
|
66
|
+
if (!Number.isFinite(opts.size) || opts.size <= 0) {
|
|
67
|
+
return invalidUsage("Buffer size must be greater than zero.");
|
|
68
|
+
}
|
|
69
|
+
if (opts.usage.length === 0)
|
|
70
|
+
return invalidUsage("Buffer usage must not be empty.");
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function invalidUsage(message) {
|
|
74
|
+
return new ValidationError({ code: "VGPU-CORE-INVALID-USAGE", message, where: "Device.createBuffer" });
|
|
75
|
+
}
|
|
76
|
+
function toGPUBufferDescriptor(opts) {
|
|
77
|
+
return { label: opts.label, size: opts.size, usage: bufferUsageFlags(opts.usage) };
|
|
78
|
+
}
|
|
79
|
+
function nativeErrorToVGPUError(error) {
|
|
80
|
+
if (!error)
|
|
81
|
+
return null;
|
|
82
|
+
return new ValidationError({ code: "VGPU-CORE-VALIDATION", message: error.message, where: "GPUDevice.popErrorScope", cause: error });
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","s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C;AACvI,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type VGPUErrorSeverity = "error" | "warning" | "info";
|
|
2
|
+
export interface VGPUErrorData {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly message: string;
|
|
5
|
+
readonly severity?: VGPUErrorSeverity;
|
|
6
|
+
readonly fix?: string;
|
|
7
|
+
readonly where?: string;
|
|
8
|
+
readonly cause?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare class VGPUError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly severity: VGPUErrorSeverity;
|
|
13
|
+
readonly fix?: string;
|
|
14
|
+
readonly where?: string;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
constructor(data: VGPUErrorData);
|
|
17
|
+
}
|
|
18
|
+
export declare class ValidationError extends VGPUError {
|
|
19
|
+
constructor(data: Omit<VGPUErrorData, "severity">);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEtB,IAAI,EAAE,aAAa;CAShC;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;CAIlD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class VGPUError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
severity;
|
|
4
|
+
fix;
|
|
5
|
+
where;
|
|
6
|
+
cause;
|
|
7
|
+
constructor(data) {
|
|
8
|
+
super(data.message, { cause: data.cause });
|
|
9
|
+
this.name = "VGPUError";
|
|
10
|
+
this.code = data.code;
|
|
11
|
+
this.severity = data.severity ?? "error";
|
|
12
|
+
this.fix = data.fix;
|
|
13
|
+
this.where = data.where;
|
|
14
|
+
this.cause = data.cause;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class ValidationError extends VGPUError {
|
|
18
|
+
constructor(data) {
|
|
19
|
+
super({ ...data, severity: "error" });
|
|
20
|
+
this.name = "ValidationError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,QAAQ,CAAoB;IAC5B,GAAG,CAAU;IACb,KAAK,CAAU;IACN,KAAK,CAAW;IAElC,YAAY,IAAmB;QAC7B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;QACzC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,IAAqC;QAC/C,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BufferUsageName, TextureUsageName } from "./types.ts";
|
|
2
|
+
export declare function bufferUsageFlags(usages: readonly BufferUsageName[]): GPUBufferUsageFlags;
|
|
3
|
+
export declare function mapReadMode(): GPUMapModeFlags;
|
|
4
|
+
export declare function textureUsageFlags(usages: readonly TextureUsageName[]): GPUTextureUsageFlags;
|
|
5
|
+
//# sourceMappingURL=gpuConstants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpuConstants.d.ts","sourceRoot":"","sources":["../src/gpuConstants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAepE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,GAAG,mBAAmB,CAIxF;AAOD,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAUD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,GAAG,oBAAoB,CAI3F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const fallbackUsage = {
|
|
2
|
+
map_read: 1,
|
|
3
|
+
map_write: 2,
|
|
4
|
+
copy_src: 4,
|
|
5
|
+
copy_dst: 8,
|
|
6
|
+
index: 16,
|
|
7
|
+
vertex: 32,
|
|
8
|
+
uniform: 64,
|
|
9
|
+
storage: 128,
|
|
10
|
+
indirect: 256,
|
|
11
|
+
query_resolve: 512,
|
|
12
|
+
};
|
|
13
|
+
export function bufferUsageFlags(usages) {
|
|
14
|
+
// WebGPU constants are numeric dictionaries when present; fallback values cover headless/mock runtimes.
|
|
15
|
+
const constants = globalThis.GPUBufferUsage;
|
|
16
|
+
return usages.reduce((flags, usage) => flags | usageFlag(usage, constants), 0);
|
|
17
|
+
}
|
|
18
|
+
function usageFlag(usage, constants) {
|
|
19
|
+
const key = usage.toUpperCase();
|
|
20
|
+
return constants?.[key] ?? fallbackUsage[usage];
|
|
21
|
+
}
|
|
22
|
+
export function mapReadMode() {
|
|
23
|
+
return (globalThis.GPUMapMode?.READ ?? 1);
|
|
24
|
+
}
|
|
25
|
+
const fallbackTextureUsage = {
|
|
26
|
+
copy_src: 1,
|
|
27
|
+
copy_dst: 2,
|
|
28
|
+
texture_binding: 4,
|
|
29
|
+
storage_binding: 8,
|
|
30
|
+
render_attachment: 16,
|
|
31
|
+
};
|
|
32
|
+
export function textureUsageFlags(usages) {
|
|
33
|
+
// WebGPU constants are numeric dictionaries when present; fallback values cover headless/mock runtimes.
|
|
34
|
+
const constants = globalThis.GPUTextureUsage;
|
|
35
|
+
return usages.reduce((flags, usage) => flags | textureUsageFlag(usage, constants), 0);
|
|
36
|
+
}
|
|
37
|
+
function textureUsageFlag(usage, constants) {
|
|
38
|
+
const key = usage.toUpperCase();
|
|
39
|
+
return constants?.[key] ?? fallbackTextureUsage[usage];
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=gpuConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpuConstants.js","sourceRoot":"","sources":["../src/gpuConstants.ts"],"names":[],"mappings":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CAAC,EAAE,CAAC,CAAyB,CAAC;AAChH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAuB,EAAE,SAAkC;IACnF,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAChC,OAAO,SAAS,EAAE,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { App } from "./app.ts";
|
|
2
|
+
export { Buffer } from "./buffer.ts";
|
|
3
|
+
export { Device } from "./device.ts";
|
|
4
|
+
export { Queue } from "./queue.ts";
|
|
5
|
+
export { Shader } from "./shader.ts";
|
|
6
|
+
export { Texture } from "./texture.ts";
|
|
7
|
+
export { VGPUError, ValidationError } from "./errors.ts";
|
|
8
|
+
export { createMockGPUDevice } from "./mockGpu.ts";
|
|
9
|
+
export type { AppCreateOptions, AppInstance, VGPUAdapter } from "./app-types.ts";
|
|
10
|
+
export type { BufferOptions, BufferUsageName, BufferWriteData, TextureOptions, TextureUsageName, CreateDeviceOptions, } from "./types.ts";
|
|
11
|
+
export type { ShaderInput } from "./shader.ts";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjF,YAAY,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { App } from "./app.js";
|
|
2
|
+
export { Buffer } from "./buffer.js";
|
|
3
|
+
export { Device } from "./device.js";
|
|
4
|
+
export { Queue } from "./queue.js";
|
|
5
|
+
export { Shader } from "./shader.js";
|
|
6
|
+
export { Texture } from "./texture.js";
|
|
7
|
+
export { VGPUError, ValidationError } from "./errors.js";
|
|
8
|
+
export { createMockGPUDevice } from "./mockGpu.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface MockGPUBuffer extends GPUBuffer {
|
|
2
|
+
readonly __vgpuMockBytes: Uint8Array;
|
|
3
|
+
}
|
|
4
|
+
export interface MockGPUTexture extends GPUTexture {
|
|
5
|
+
readonly __vgpuMockBytes: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
export declare function isMockGPUBuffer(buffer: GPUBuffer): buffer is MockGPUBuffer;
|
|
8
|
+
export declare function isMockGPUTexture(texture: GPUTexture): texture is MockGPUTexture;
|
|
9
|
+
//# sourceMappingURL=mock-gpu-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-gpu-storage.d.ts","sourceRoot":"","sources":["../src/mock-gpu-storage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;CACtC;AAED,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;CACtC;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,aAAa,CAE1E;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,cAAc,CAE/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-gpu-storage.js","sourceRoot":"","sources":["../src/mock-gpu-storage.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,eAAe,CAAC,MAAiB;IAC/C,OAAO,iBAAiB,IAAI,MAAM,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IAClD,OAAO,iBAAiB,IAAI,OAAO,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockGpu.d.ts","sourceRoot":"","sources":["../src/mockGpu.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,IAAI,SAAS,CAgD/C;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAEtE"}
|
package/dist/mockGpu.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { bufferUsageFlags } from "./gpuConstants.js";
|
|
2
|
+
import { isMockGPUBuffer } from "./mock-gpu-storage.js";
|
|
3
|
+
export function createMockGPUDevice() {
|
|
4
|
+
return {
|
|
5
|
+
createBuffer: createMockBuffer,
|
|
6
|
+
createTexture(desc) {
|
|
7
|
+
const size = textureSize(desc.size);
|
|
8
|
+
const bytes = new Uint8Array(size.width * size.height * 4);
|
|
9
|
+
return {
|
|
10
|
+
__vgpuMockBytes: bytes,
|
|
11
|
+
label: desc.label ?? "",
|
|
12
|
+
width: size.width,
|
|
13
|
+
height: size.height,
|
|
14
|
+
depthOrArrayLayers: size.depthOrArrayLayers,
|
|
15
|
+
mipLevelCount: 1,
|
|
16
|
+
sampleCount: desc.sampleCount ?? 1,
|
|
17
|
+
dimension: "2d",
|
|
18
|
+
format: desc.format,
|
|
19
|
+
usage: desc.usage,
|
|
20
|
+
createView: () => ({}),
|
|
21
|
+
destroy() { },
|
|
22
|
+
// Mock WebGPU texture: only fields touched by core/render tests are implemented.
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
createShaderModule: () => ({}),
|
|
26
|
+
createBindGroupLayout: () => ({}),
|
|
27
|
+
createPipelineLayout: () => ({}),
|
|
28
|
+
createBindGroup: () => ({}),
|
|
29
|
+
createSampler: () => ({}),
|
|
30
|
+
createRenderPipeline: () => ({}),
|
|
31
|
+
createCommandEncoder() {
|
|
32
|
+
return {
|
|
33
|
+
copyBufferToBuffer() { },
|
|
34
|
+
copyTextureToBuffer() { },
|
|
35
|
+
// Mock render pass encoder: only binding/pipeline/draw/end methods used by tests are implemented.
|
|
36
|
+
beginRenderPass: () => ({ setBindGroup() { }, setVertexBuffer() { }, setPipeline() { }, draw() { }, end() { } }),
|
|
37
|
+
finish: () => ({}),
|
|
38
|
+
// Mock command encoder: only copy/render/finish methods used by core are implemented.
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
destroy() { },
|
|
42
|
+
queue: {
|
|
43
|
+
submit() { },
|
|
44
|
+
writeBuffer(buffer, offset, data, dataOffset = 0, size) {
|
|
45
|
+
if (isMockGPUBuffer(buffer))
|
|
46
|
+
buffer.__vgpuMockBytes.set(bytesFrom(data).subarray(dataOffset, size ? dataOffset + size : undefined), offset);
|
|
47
|
+
},
|
|
48
|
+
onSubmittedWorkDone: async () => undefined,
|
|
49
|
+
},
|
|
50
|
+
// Mock device: shape is intentionally partial but covers every member used by adapters/tests.
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function mockBufferDescriptor(size) {
|
|
54
|
+
return { size, usage: bufferUsageFlags(["copy_src", "copy_dst"]) };
|
|
55
|
+
}
|
|
56
|
+
function createMockBuffer(desc) {
|
|
57
|
+
const bytes = new Uint8Array(Number(desc.size));
|
|
58
|
+
return {
|
|
59
|
+
__vgpuMockBytes: bytes,
|
|
60
|
+
label: desc.label ?? "",
|
|
61
|
+
size: desc.size,
|
|
62
|
+
usage: desc.usage,
|
|
63
|
+
mapState: "unmapped",
|
|
64
|
+
destroy() { },
|
|
65
|
+
getMappedRange: () => bytes.buffer,
|
|
66
|
+
mapAsync: async () => undefined,
|
|
67
|
+
unmap() { },
|
|
68
|
+
// Mock WebGPU buffer: byte storage plus map/destroy methods are enough for read/write tests.
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function textureSize(size) {
|
|
72
|
+
if (Array.isArray(size))
|
|
73
|
+
return { width: size[0], height: size[1] ?? 1, depthOrArrayLayers: size[2] ?? 1 };
|
|
74
|
+
const dict = size;
|
|
75
|
+
return { width: dict.width, height: dict.height ?? 1, depthOrArrayLayers: dict.depthOrArrayLayers ?? 1 };
|
|
76
|
+
}
|
|
77
|
+
function bytesFrom(data) {
|
|
78
|
+
if (data instanceof ArrayBuffer)
|
|
79
|
+
return new Uint8Array(data);
|
|
80
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=mockGpu.js.map
|
|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+
writeBuffer(buffer: GPUBuffer, offset: number, data: BufferWriteData): void;
|
|
6
|
+
flush(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,KAAK;IACJ,QAAQ,CAAC,GAAG,EAAE,QAAQ;gBAAb,GAAG,EAAE,QAAQ;IAElC,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAIrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class Queue {
|
|
2
|
+
gpu;
|
|
3
|
+
constructor(gpu) {
|
|
4
|
+
this.gpu = gpu;
|
|
5
|
+
}
|
|
6
|
+
writeBuffer(buffer, offset, data) {
|
|
7
|
+
this.gpu.writeBuffer(buffer, offset, data);
|
|
8
|
+
}
|
|
9
|
+
async flush() {
|
|
10
|
+
await this.gpu.onSubmittedWorkDone?.();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,KAAK;IACK;IAArB,YAAqB,GAAa;QAAb,QAAG,GAAH,GAAG,CAAU;IAAG,CAAC;IAEtC,WAAW,CAAC,MAAiB,EAAE,MAAc,EAAE,IAAqB;QAClE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class Readback {
|
|
2
|
+
private readonly device;
|
|
3
|
+
constructor(device: GPUDevice);
|
|
4
|
+
read(source: GPUBuffer, byteLength: number, offset: number): Promise<ArrayBuffer>;
|
|
5
|
+
readTexture(texture: GPUTexture, size: readonly [number, number, number?], format: GPUTextureFormat): Promise<Uint8Array>;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=readback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readback.d.ts","sourceRoot":"","sources":["../src/readback.ts"],"names":[],"mappings":"AAMA,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAExC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAmBjF,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAsB/H,OAAO,IAAI,IAAI;CAChB"}
|