@derschmale/tiny-helix 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/dist/BindGroup.d.ts +121 -0
  4. package/dist/BlendMode.d.ts +21 -0
  5. package/dist/Buffer.d.ts +66 -0
  6. package/dist/BufferDataWriter.d.ts +67 -0
  7. package/dist/CommandEncoder.d.ts +50 -0
  8. package/dist/ComputePass.d.ts +37 -0
  9. package/dist/ComputePipeline.d.ts +18 -0
  10. package/dist/Mesh.d.ts +177 -0
  11. package/dist/Pipeline.d.ts +47 -0
  12. package/dist/RenderPass.d.ts +101 -0
  13. package/dist/RenderPipeline.d.ts +77 -0
  14. package/dist/RenderTarget.d.ts +44 -0
  15. package/dist/Renderer.d.ts +44 -0
  16. package/dist/Sampler.d.ts +31 -0
  17. package/dist/Shader.d.ts +77 -0
  18. package/dist/Texture.d.ts +55 -0
  19. package/dist/TinyHelix.d.ts +163 -0
  20. package/dist/UniformBuffer.d.ts +84 -0
  21. package/dist/WebGPUContext.d.ts +70 -0
  22. package/dist/buffers/Buffer.d.ts +79 -0
  23. package/dist/buffers/BufferDataWriter.d.ts +68 -0
  24. package/dist/buffers/IBuffer.d.ts +4 -0
  25. package/dist/buffers/UniformBuffer.d.ts +111 -0
  26. package/dist/enums.d.ts +158 -0
  27. package/dist/index.d.ts +24 -0
  28. package/dist/main.js +2 -0
  29. package/dist/main.js.map +1 -0
  30. package/dist/tiny-helix.debug.js +3351 -0
  31. package/dist/tiny-helix.debug.js.map +1 -0
  32. package/dist/tiny-helix.esm.debug.js +3386 -0
  33. package/dist/tiny-helix.esm.debug.js.map +1 -0
  34. package/dist/tiny-helix.esm.js +2 -0
  35. package/dist/tiny-helix.esm.js.map +1 -0
  36. package/dist/tiny-helix.js +2 -0
  37. package/dist/tiny-helix.js.map +1 -0
  38. package/dist/utils/IndexedCollection.d.ts +4 -0
  39. package/dist/utils/float32ToFloat16.d.ts +5 -0
  40. package/dist/utils/mapUndefined.d.ts +6 -0
  41. package/dist/utils/padArrayBuffer.d.ts +10 -0
  42. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 David Lenaerts
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,95 @@
1
+ # tiny-helix
2
+
3
+ A lightweight TypeScript library for WebGPU, built as an ES6 module.
4
+
5
+ ## Quickstart
6
+
7
+ Install:
8
+
9
+ ```bash
10
+ npm install tiny-helix
11
+ ```
12
+
13
+ Or for development from source:
14
+
15
+ ```bash
16
+ git clone https://github.com/DerSchmale/tiny-helix.git
17
+ cd tiny-helix
18
+ npm install
19
+ npm run build:debug # builds non-minified debug bundles with source maps
20
+ ```
21
+
22
+ ## Usage (browser)
23
+
24
+ Basic example showing initialization and a simple render loop:
25
+
26
+ ```ts
27
+ import TinyHelix from 'tiny-helix';
28
+
29
+ const app = new TinyHelix();
30
+ await app.initialize({ canvas: document.querySelector('canvas')! });
31
+
32
+ function frame() {
33
+ app.startFrame();
34
+ const encoder = app.createCommandEncoder('frame-encoder');
35
+
36
+ // Simple clear pass: create a render pass, set the clear color and end the pass.
37
+ // This uses the backbuffer as the default target.
38
+ const clearPass = encoder.createRenderPass()
39
+ .withLabel('clear-pass')
40
+ .withClearColor(0.1, 0.12, 0.15, 1.0) // r,g,b,a
41
+ .build();
42
+
43
+ clearPass.end();
44
+
45
+ encoder.submit();
46
+ requestAnimationFrame(frame);
47
+ }
48
+
49
+ frame();
50
+ ```
51
+
52
+ ## Debug build and source maps
53
+
54
+ A development-friendly debug build is included. It produces readable, non-minified bundles with full source maps. The debug builds output the following files into `dist/`:
55
+
56
+ - `tiny-helix.debug.js` + `tiny-helix.debug.js.map` (UMD / CommonJS-like build)
57
+ - `tiny-helix.esm.debug.js` + `tiny-helix.esm.debug.js.map` (ESM build)
58
+
59
+ To create the debug bundles run:
60
+
61
+ ```bash
62
+ npm run build:debug
63
+ ```
64
+
65
+ The webpack configuration is set up so source maps use `file:///...` absolute file URLs instead of the `webpack://` scheme. This prevents browsers from attempting to resolve `webpack://` sources when consuming the package as a module.
66
+
67
+ ## API overview
68
+
69
+ This project exposes a small set of helpers and wrappers for working with WebGPU in TypeScript. The main entry points are:
70
+
71
+ - `TinyHelix` (default export): High-level manager for a WebGPU context, backbuffer and helpers for creating render targets, shaders, meshes and render pipelines.
72
+ - `WebGPUContext`: Low-level context manager that handles adapter/device initialization and canvas configuration.
73
+ - `CommandEncoder`: Helper for recording and submitting GPU commands per-frame.
74
+ - `RenderPass`, `RenderPipeline`, `RenderTarget`, `Shader`, `Mesh`, `Texture`, and buffer helpers.
75
+
76
+ See the inline JSDoc comments in `src/` for detailed method and type information. TypeScript consumers will get typings from the `dist/index.d.ts` entry.
77
+
78
+ ## Development notes
79
+
80
+ - Use `npm run build` to produce production bundles (minified, optimized).
81
+ - Use `npm run build:debug` to produce debug bundles with full source maps.
82
+ - For TypeScript projects, install `@webgpu/types` for better type completion:
83
+
84
+ ```bash
85
+ npm install --save-dev @webgpu/types
86
+ ```
87
+
88
+ ## Requirements
89
+
90
+ - A browser with WebGPU support
91
+ - For TypeScript projects, you may want to install `@webgpu/types` for full type definitions
92
+
93
+ ## License
94
+
95
+ MIT License - see [LICENSE](./LICENSE) for details.
@@ -0,0 +1,121 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import { WebGPUContext } from "./WebGPUContext";
3
+ import { UniformBuffer, UniformBufferLayout } from "./buffers/UniformBuffer";
4
+ import { IBuffer } from "./buffers/IBuffer";
5
+ import { Texture, TextureView } from "./Texture";
6
+ import { Sampler } from "./Sampler";
7
+ import { TextureFormat } from "../dist";
8
+ import { StorageAccess } from "./enums";
9
+ /**
10
+ * Lightweight wrapper around a GPUBindGroup.
11
+ * Use {@link TinyHelix.createBindGroup} to create instances.
12
+ */
13
+ export declare class BindGroup {
14
+ /** @internal */
15
+ readonly _inner: GPUBindGroup;
16
+ /**
17
+ * Construct a wrapper around an existing GPUBindGroup.
18
+ * @internal
19
+ */
20
+ constructor(inner: GPUBindGroup);
21
+ }
22
+ /**
23
+ * Builder for creating GPUBindGroup instances. Supports adding uniform buffer
24
+ * entries and a human-readable label.
25
+ */
26
+ export declare class BindGroupBuilder {
27
+ private _entries;
28
+ private _label?;
29
+ private _layout;
30
+ private _ctx;
31
+ /**
32
+ * @internal
33
+ */
34
+ constructor(ctx: WebGPUContext, layout: BindGroupLayout);
35
+ /**
36
+ * Assign a human-readable label for the bind group (useful in GPU debuggers).
37
+ */
38
+ withLabel(label: string): this;
39
+ /**
40
+ * Attach a buffer to the bind group
41
+ * @param fieldName
42
+ * @param buffer
43
+ */
44
+ withBuffer(fieldName: string, buffer: IBuffer): this;
45
+ /** Attach a texture to the bind group. */
46
+ withTexture(fieldName: string, texture: Texture | TextureView): this;
47
+ /** Attach a sampler to the bind group at the given binding index. */
48
+ withSampler(fieldName: string, sampler: Sampler): this;
49
+ /**
50
+ * Create the GPUBindGroup and return a wrapped `BindGroup` instance.
51
+ */
52
+ build(): BindGroup;
53
+ }
54
+ /**
55
+ * Wrapper around a GPUBindGroupLayout that also keeps track of any
56
+ * UniformBufferLayout objects associated with the layout. Useful for
57
+ * constructing `BindGroupBuilder` instances for specific layouts.
58
+ */
59
+ export declare class BindGroupLayout {
60
+ /** @internal */
61
+ readonly _inner: GPUBindGroupLayout;
62
+ private _uboLayouts;
63
+ private _ctx;
64
+ private _indices;
65
+ constructor(inner: GPUBindGroupLayout, ctx: WebGPUContext, indices: Map<string, number>, uboLayouts: Map<string, UniformBufferLayout>);
66
+ /**
67
+ * Get the UniformBufferLayout associated with a named field (if any).
68
+ */
69
+ getUniformBufferLayout(name: string): UniformBufferLayout | undefined;
70
+ createUniformBuffer(name: string): UniformBuffer | undefined;
71
+ _getBindingIndex(fieldName: string): number;
72
+ }
73
+ /**
74
+ * Builder for GPUBindGroupLayout. Currently supports adding uniform buffers
75
+ * and their associated layout information.
76
+ */
77
+ declare class BindGroupLayoutBuilder {
78
+ private _entries;
79
+ private _indices;
80
+ private _uboLayouts;
81
+ private _label?;
82
+ private _ctx;
83
+ constructor(ctx: WebGPUContext);
84
+ /**
85
+ * Assign a label for the bind group layout.
86
+ */
87
+ withLabel(label: string): this;
88
+ /**
89
+ * Add a uniform buffer binding at the given index and record its layout.
90
+ * @param index - binding index
91
+ * @param field_name - a name used to reference the layout later
92
+ * @param layout - the UniformBufferLayout describing the UBO
93
+ * @param visibility - shader stage visibility flags (defaults to VERTEX|FRAGMENT|COMPUTE)
94
+ */
95
+ withUniformBuffer(index: number, field_name: string, layout: UniformBufferLayout, visibility?: GPUShaderStageFlags): this;
96
+ /**
97
+ * Add a storage buffer binding at the given index and record its layout.
98
+ * @param index - binding index
99
+ * @param field_name - a name used to reference the layout later
100
+ * @param access_mode - Defines whether the storage buffer is read-only or not.
101
+ * @param visibility - shader stage visibility flags (defaults to FRAGMENT|COMPUTE)
102
+ */
103
+ withStorageBuffer(index: number, field_name: string, access_mode: StorageAccess, visibility?: GPUShaderStageFlags): this;
104
+ /**
105
+ * Add a storage texture binding at the given index. The texture will be
106
+ * write-only and use RGBA8Unorm format.
107
+ * @param index
108
+ * @param field_name
109
+ * @param format
110
+ * @param access_mode
111
+ * @param visibility
112
+ */
113
+ withStorageTexture(index: number, field_name: string, format: TextureFormat, access_mode: StorageAccess, visibility?: GPUShaderStageFlags): this;
114
+ withTexture(index: number, field_name: string, visibility?: GPUShaderStageFlags): this;
115
+ withSampler(index: number, field_name: string, visibility?: GPUShaderStageFlags): this;
116
+ /**
117
+ * Create the underlying GPUBindGroupLayout and return a wrapped `BindGroupLayout`.
118
+ */
119
+ build(): BindGroupLayout;
120
+ }
121
+ export default BindGroupLayoutBuilder;
@@ -0,0 +1,21 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import { BlendFactor } from "./enums";
3
+ export declare class BlendMode {
4
+ readonly _inner: GPUBlendState;
5
+ static ALPHA: BlendMode;
6
+ static ADDITIVE: BlendMode;
7
+ static MULTIPLY: BlendMode;
8
+ static SCREEN: BlendMode;
9
+ static OVERLAY: BlendMode;
10
+ static DARKEN: BlendMode;
11
+ static LIGHTEN: BlendMode;
12
+ get srcFactor(): BlendFactor;
13
+ set srcFactor(value: BlendFactor);
14
+ get dstFactor(): BlendFactor;
15
+ set dstFactor(value: BlendFactor);
16
+ get alphaSrcFactor(): BlendFactor;
17
+ set alphaSrcFactor(value: BlendFactor);
18
+ get alphaDstFactor(): BlendFactor;
19
+ set alphaDstFactor(value: BlendFactor);
20
+ constructor(srcFactor: BlendFactor, dstFactor: BlendFactor, alphaSrcFactor: BlendFactor, alphaDstFactor: BlendFactor);
21
+ }
@@ -0,0 +1,66 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import { WebGPUContext } from "./WebGPUContext";
3
+ /**
4
+ * Buffer usage flags re-exported from the WebGPU API for convenience.
5
+ * Use these when constructing buffers with `BufferBuilder.withUsage()`.
6
+ */
7
+ export declare enum BufferUsage {
8
+ MapRead,
9
+ MapWrite,
10
+ CopySrc,
11
+ CopyDst,
12
+ Index,
13
+ Vertex,
14
+ Uniform,
15
+ Storage,
16
+ Indirect,
17
+ QueryResolve
18
+ }
19
+ /**
20
+ * Builder for creating GPU-backed buffers.
21
+ *
22
+ * Example:
23
+ * const buf = new BufferBuilder(ctx)
24
+ * .withUsage(BufferUsage.Vertex | BufferUsage.CopyDst)
25
+ * .withData(new Float32Array([...]).buffer)
26
+ * .build();
27
+ */
28
+ export declare class BufferBuilder {
29
+ private _ctx;
30
+ private _data?;
31
+ private _size;
32
+ private _keepData;
33
+ private _usage;
34
+ constructor(ctx: WebGPUContext);
35
+ /**
36
+ * Add usage flags for the GPU buffer.
37
+ */
38
+ withUsage(usage: BufferUsage): this;
39
+ /**
40
+ * Provide initial data for the buffer. If `keepOnCPU` is true the original
41
+ * ArrayBuffer is stored in the resulting `Buffer.data` field for readback or
42
+ * reuse.
43
+ */
44
+ withData(data: ArrayBufferLike, keepOnCPU?: boolean): this;
45
+ /**
46
+ * Create the GPU buffer and upload any provided data.
47
+ */
48
+ build(): Buffer;
49
+ }
50
+ /**
51
+ * Lightweight wrapper around a GPUBuffer. Exposes the original CPU-side data
52
+ * (when kept) and the underlying GPU buffer for low-level interop.
53
+ */
54
+ export declare class Buffer {
55
+ readonly _inner: GPUBuffer;
56
+ readonly data?: ArrayBufferLike;
57
+ /**
58
+ * Create a Buffer from an existing GPUBuffer.
59
+ * @param inner The underlying GPUBuffer.
60
+ * @param data Optional CPU-side copy of the buffer contents.
61
+ */
62
+ constructor(inner: GPUBuffer, data?: ArrayBufferLike);
63
+ /** Size of the GPU buffer in bytes. */
64
+ get size(): number;
65
+ _uploadData(ctx: WebGPUContext): void;
66
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Utility for incrementally building binary data into an ArrayBuffer.
3
+ * Provides typed push helpers for common numeric types used in vertex/index buffers.
4
+ */
5
+ export declare class BufferDataWriter {
6
+ private _buffer;
7
+ private _view;
8
+ private _offset;
9
+ /** Create a new writer with the given total byte size. */
10
+ constructor(byteSize: number);
11
+ /** Push an unsigned 8-bit integer. */
12
+ pushUint8(value: number): this;
13
+ /** Push two unsigned 8-bit integers. */
14
+ pushUint8x2(x: number, y: number): this;
15
+ /** Push four unsigned 8-bit integers. */
16
+ pushUint8x4(x: number, y: number, z: number, w: number): this;
17
+ /** Push a signed 8-bit integer. */
18
+ pushSint8(value: number): this;
19
+ /** Push two signed 8-bit integers. */
20
+ pushSint8x2(x: number, y: number): this;
21
+ /** Push four signed 8-bit integers. */
22
+ pushSint8x4(x: number, y: number, z: number, w: number): this;
23
+ /** Push an unsigned 16-bit integer (little-endian). */
24
+ pushUint16(value: number): this;
25
+ /** Push two unsigned 16-bit integers (little-endian). */
26
+ pushUint16x2(x: number, y: number): this;
27
+ /** Push four unsigned 16-bit integers (little-endian). */
28
+ pushUint16x4(x: number, y: number, z: number, w: number): this;
29
+ /** Push a signed 16-bit integer (little-endian). */
30
+ pushSint16(value: number): this;
31
+ /** Push two signed 16-bit integers (little-endian). */
32
+ pushSint16x2(x: number, y: number): this;
33
+ /** Push four signed 16-bit integers (little-endian). */
34
+ pushSint16x4(x: number, y: number, z: number, w: number): this;
35
+ /** Push a 16-bit float (little-endian). */
36
+ pushFloat16(value: number): this;
37
+ /** Push two 16-bit floats (little-endian). */
38
+ pushFloat16x2(x: number, y: number): this;
39
+ /** Push four 16-bit floats (little-endian). */
40
+ pushFloat16x4(x: number, y: number, z: number, w: number): this;
41
+ /** Push a 32-bit float (little-endian). */
42
+ pushFloat32(value: number): this;
43
+ /** Push two 32-bit floats (little-endian). */
44
+ pushFloat32x2(x: number, y: number): this;
45
+ /** Push four 32-bit floats (little-endian). */
46
+ pushFloat32x3(x: number, y: number, z: number): this;
47
+ /** Push an 8-bit float (little-endian). */
48
+ pushFloat32x4(x: number, y: number, z: number, w: number): this;
49
+ /** Push an unsigned 32-bit integer (little-endian). */
50
+ pushUint32(value: number): this;
51
+ /** Push two unsigned 32-bit integers (little-endian). */
52
+ pushUint32x2(x: number, y: number): this;
53
+ /** Push three unsigned 32-bit integers (little-endian). */
54
+ pushUint32x3(x: number, y: number, z: number): this;
55
+ /** Push four unsigned 32-bit integers (little-endian). */
56
+ pushUint32x4(x: number, y: number, z: number, w: number): this;
57
+ /** Push a signed 32-bit integer (little-endian). */
58
+ pushSint32(value: number): this;
59
+ /** Push two signed 32-bit integers (little-endian). */
60
+ pushSint32x2(x: number, y: number): this;
61
+ /** Push three signed 32-bit integers (little-endian). */
62
+ pushSint32x3(x: number, y: number, z: number): this;
63
+ /** Push four signed 32-bit integers (little-endian). */
64
+ pushSint32x4(x: number, y: number, z: number, w: number): this;
65
+ /** Returns the underlying ArrayBuffer containing all written data. */
66
+ get arrayBuffer(): ArrayBuffer;
67
+ }
@@ -0,0 +1,50 @@
1
+ import { WebGPUContext } from "./WebGPUContext";
2
+ import { RenderPassBuilder } from "./RenderPass";
3
+ import { RenderTarget } from "./RenderTarget";
4
+ import { ComputePassBuilder } from "./ComputePass";
5
+ import { BindGroup } from "./BindGroup";
6
+ import { Buffer } from "./buffers/Buffer";
7
+ /**
8
+ * Encapsulates a GPUCommandEncoder and provides helper methods to build and
9
+ * submit GPU commands for a single frame. CommandEncoder should only be created
10
+ * through the TinyHelix instance (See {@link TinyHelix.createCommandEncoder})
11
+ */
12
+ export declare class CommandEncoder {
13
+ private _encoder;
14
+ private _queue;
15
+ private _backbufferTarget;
16
+ private _commandBuffer;
17
+ private _depthStencilTarget;
18
+ private _globalBindGroups;
19
+ /**
20
+ * Create a new CommandEncoder bound to a backbuffer/render target and
21
+ * the WebGPU context.
22
+ *
23
+ * @internal
24
+ */
25
+ constructor(backbufferTarget: RenderTarget, globalBindGroups: BindGroup[], ctx: WebGPUContext, depthStencilTarget?: RenderTarget, label?: string);
26
+ /**
27
+ * Clears a buffer's contents
28
+ */
29
+ clearBuffer(buffer: Buffer, offset?: number, size?: number): this;
30
+ /**
31
+ * Begin building a render pass attached to this encoder.
32
+ * Returns a fluent RenderPassBuilder used to configure attachments and clear ops.
33
+ */
34
+ createRenderPass(): RenderPassBuilder;
35
+ /**
36
+ * Begin building a compute pass attached to this encoder.
37
+ * Returns a fluent ComputePassBuilder used to configure bindings and dispatch ops.
38
+ */
39
+ createComputePass(): ComputePassBuilder;
40
+ /**
41
+ * Mark the encoder as finished and finalize any pending commands.
42
+ * Calling finish() multiple times is safe but a no-op after the first call.
43
+ */
44
+ finish(): void;
45
+ /**
46
+ * Submit the recorded commands to the GPU queue. If the encoder has not
47
+ * been finished yet, finish() will be called automatically.
48
+ */
49
+ submit(): void;
50
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import { BindGroup } from "./BindGroup";
3
+ import { ComputePipeline } from "./ComputePipeline";
4
+ import { Buffer } from "./buffers/Buffer";
5
+ export declare class ComputePass {
6
+ private readonly _inner;
7
+ constructor(inner: GPUComputePassEncoder);
8
+ /**
9
+ * Set the compute pipeline to use for the next dispatch calls.
10
+ * @param pipeline
11
+ */
12
+ setPipeline(pipeline: ComputePipeline): this;
13
+ dispatch(x: GPUSize32, y?: GPUSize32, z?: GPUSize32): this;
14
+ dispatchIndirect(buffer: Buffer, offset: number): this;
15
+ /**
16
+ * Set a bind group at the given index.
17
+ * @param index - bind group index in the render pipeline layout
18
+ * @param bindGroup - a `BindGroup` instance
19
+ */
20
+ setBindGroup(index: number, bindGroup: BindGroup): this;
21
+ /**
22
+ * End the compute pass. After calling end(), the underlying encoder may
23
+ * continue recording other passes or be finished/submitted.
24
+ */
25
+ end(): void;
26
+ }
27
+ export declare class ComputePassBuilder {
28
+ private _label?;
29
+ private _encoder;
30
+ private _globalBindGroups;
31
+ constructor(encoder: GPUCommandEncoder, globalBindGroups: BindGroup[]);
32
+ /**
33
+ * Assign a human-readable label for the render pass (useful for GPU debuggers).
34
+ */
35
+ withLabel(label: string): this;
36
+ build(): ComputePass;
37
+ }
@@ -0,0 +1,18 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import { WebGPUContext } from "./WebGPUContext";
3
+ import { Shader } from "./Shader";
4
+ export declare class ComputePipeline {
5
+ readonly _inner: GPUComputePipeline;
6
+ constructor(inner: GPUComputePipeline);
7
+ }
8
+ export declare class ComputePipelineBuilder {
9
+ private _ctx;
10
+ private _label?;
11
+ private _shader;
12
+ private _entry;
13
+ constructor(ctx: WebGPUContext);
14
+ withLabel(label: string): this;
15
+ /** Select the shader entry point for the fragment stage. */
16
+ withShader(shader: Shader, entry: string): this;
17
+ build(): ComputePipeline;
18
+ }
package/dist/Mesh.d.ts ADDED
@@ -0,0 +1,177 @@
1
+ import { Buffer } from "./buffers/Buffer";
2
+ import { WebGPUContext } from "./WebGPUContext";
3
+ /**
4
+ * Index buffer formats supported by the library.
5
+ */
6
+ export declare enum IndexFormat {
7
+ Uint16 = "uint16",
8
+ Uint32 = "uint32"
9
+ }
10
+ declare class IndexBuffer {
11
+ buffer: Buffer;
12
+ format: IndexFormat;
13
+ count: number;
14
+ constructor(data: Uint16Array | Uint32Array, ctx: WebGPUContext, keepData?: boolean);
15
+ }
16
+ /**
17
+ * Mesh topology enum (maps to GPU primitive topologies).
18
+ */
19
+ export declare enum MeshTopology {
20
+ TriangleList = "triangle-list",
21
+ TriangleStrip = "triangle-strip",
22
+ LineList = "line-list",
23
+ LineStrip = "line-strip",
24
+ PointList = "point-list"
25
+ }
26
+ /**
27
+ * Winding mode for front-facing triangles.
28
+ */
29
+ export declare enum FrontFace {
30
+ Clockwise = "cw",
31
+ CounterClockwise = "ccw"
32
+ }
33
+ /**
34
+ * Vertex attribute formats supported by the helper. These are translated into
35
+ * GPU vertex attribute formats when building pipelines.
36
+ */
37
+ export declare enum VertexFormat {
38
+ Uint8 = "uint8",
39
+ Uint8x2 = "uint8x2",
40
+ Uint8x4 = "uint8x4",
41
+ Sint8 = "sint8",
42
+ Sint8x2 = "sint8x2",
43
+ Sint8x4 = "sint8x4",
44
+ Unorm8 = "unorm8",
45
+ Unorm8x2 = "unorm8x2",
46
+ Unorm8x4 = "unorm8x4",
47
+ Snorm8 = "snorm8",
48
+ Snorm8x2 = "snorm8x2",
49
+ Snorm8x4 = "snorm8x4",
50
+ Uint16 = "uint16",
51
+ Uint16x2 = "uint16x2",
52
+ Uint16x4 = "uint16x4",
53
+ Sint16 = "sint16",
54
+ Sint16x2 = "sint16x2",
55
+ Sint16x4 = "sint16x4",
56
+ Unorm16 = "unorm16",
57
+ Unorm16x2 = "unorm16x2",
58
+ Unorm16x4 = "unorm16x4",
59
+ Snorm16 = "snorm16",
60
+ Snorm16x2 = "snorm16x2",
61
+ Snorm16x4 = "snorm16x4",
62
+ Float16 = "float16",
63
+ Float16x2 = "float16x2",
64
+ Float16x4 = "float16x4",
65
+ Float32 = "float32",
66
+ Float32x2 = "float32x2",
67
+ Float32x3 = "float32x3",
68
+ Float32x4 = "float32x4",
69
+ Uint32 = "uint32",
70
+ Uint32x2 = "uint32x2",
71
+ Uint32x3 = "uint32x3",
72
+ Uint32x4 = "uint32x4",
73
+ Sint32 = "sint32",
74
+ Sint32x2 = "sint32x2",
75
+ Sint32x3 = "sint32x3",
76
+ Sint32x4 = "sint32x4",
77
+ Unorm10_10_10_2 = "unorm10-10-10-2",
78
+ Unorm8x4_bgra = "unorm8x4-bgra"
79
+ }
80
+ /**
81
+ * Lightweight Mesh representation containing vertex streams and an optional index buffer.
82
+ * Use `MeshBuilder` to construct instances.
83
+ */
84
+ export declare class Mesh {
85
+ private _topology;
86
+ private _frontFace;
87
+ private _streams;
88
+ private _indexBuffer?;
89
+ private _numVertices;
90
+ /**
91
+ * @internal
92
+ */
93
+ constructor(topology: MeshTopology, frontFace: FrontFace, streams: VertexStream[], indexBuffer?: IndexBuffer);
94
+ /** The primitive topology for this mesh. */
95
+ get topology(): MeshTopology;
96
+ /** The winding used to determine front-facing triangles. */
97
+ get frontFace(): FrontFace;
98
+ /** The number of vertex streams in this mesh. */
99
+ get numStreams(): number;
100
+ /** Get the number of vertices in the first vertex stream. */
101
+ get numVertices(): number;
102
+ /** Get the GPU-backed vertex buffer for a given stream index. */
103
+ getVertexBuffer(streamIndex: number): Buffer;
104
+ /** Get the stride (byte size) of a vertex in the requested stream. */
105
+ getStreamStride(streamIndex: number): number;
106
+ /** Get the declared attributes for a vertex stream. */
107
+ getStreamAttributes(streamIndex: number): VertexAttribute[];
108
+ /** Get the optional index buffer backing this mesh. */
109
+ get indexBuffer(): Buffer | undefined;
110
+ /** Get the index format of the index buffer backing this mesh. */
111
+ get indexFormat(): IndexFormat;
112
+ /** Get the number of indices in the index buffer backing this mesh. */
113
+ get numIndices(): number;
114
+ }
115
+ export type VertexAttribute = {
116
+ name: string;
117
+ format: VertexFormat;
118
+ offset: number;
119
+ };
120
+ declare class VertexStream {
121
+ stride: number;
122
+ attributes: VertexAttribute[];
123
+ buffer?: Buffer;
124
+ pushAttribute(name: string, format: VertexFormat): void;
125
+ get numVertices(): number;
126
+ }
127
+ /**
128
+ * Builder helper used when creating a vertex stream for a Mesh.
129
+ */
130
+ export declare class StreamBuilder {
131
+ private _stream;
132
+ private _ctx;
133
+ /**
134
+ * @internal
135
+ */
136
+ constructor(stream: VertexStream, ctx: WebGPUContext);
137
+ /**
138
+ * Add a vertex attribute to the stream.
139
+ * @param name - attribute name used by the shader bindings
140
+ * @param format - attribute format (see VertexFormat)
141
+ */
142
+ pushAttribute(name: string, format: VertexFormat): this;
143
+ /**
144
+ * Upload vertex data for this stream. `keepOnCPU` controls whether the
145
+ * source ArrayBuffer is retained in memory for readback.
146
+ */
147
+ withData(data: ArrayBufferLike, keepOnCPU?: boolean): void;
148
+ }
149
+ /**
150
+ * Fluent builder for creating a Mesh. Use `pushStream()` to describe vertex
151
+ * streams and `withIndexData()` to add optional indices.
152
+ */
153
+ export declare class MeshBuilder {
154
+ private _topology;
155
+ private _frontFace;
156
+ private _streams;
157
+ private _ctx;
158
+ private _indexBuffer?;
159
+ /**
160
+ * @internal
161
+ */
162
+ constructor(ctx: WebGPUContext);
163
+ /** Add a vertex stream using a builder callback. */
164
+ pushStream(buildFunc: (builder: StreamBuilder) => void): this;
165
+ /** Set the winding used to determine front-facing triangles. Defaults to counter-clockwise. */
166
+ withFrontFace(value: FrontFace): this;
167
+ /** Set the primitive topology for the mesh. Defaults to triangle list. */
168
+ withTopology(value: MeshTopology): this;
169
+ /**
170
+ * Provide index data (Uint16Array or Uint32Array). If `keepOnCPU` is true the
171
+ * original array buffer will be preserved on the resulting mesh's index buffer.
172
+ */
173
+ withIndexData(data: Uint16Array | Uint32Array, keepOnCPU?: boolean): this;
174
+ /** Build the mesh. */
175
+ build(): Mesh;
176
+ }
177
+ export {};