@derschmale/tiny-helix 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/LICENSE +21 -21
- package/README.md +95 -95
- package/dist/BindGroup.d.ts +12 -11
- package/dist/ComputePipeline.d.ts +2 -0
- package/dist/Mesh.d.ts +1 -1
- package/dist/RenderPass.d.ts +16 -1
- package/dist/RenderPipeline.d.ts +14 -2
- package/dist/Sampler.d.ts +4 -12
- package/dist/Shader.d.ts +2 -1
- package/dist/Texture.d.ts +38 -9
- package/dist/TinyHelix.d.ts +26 -6
- package/dist/WebGPUContext.d.ts +11 -0
- package/dist/buffers/Buffer.d.ts +2 -1
- package/dist/enums.d.ts +39 -0
- package/dist/tiny-helix.debug.js +825 -313
- package/dist/tiny-helix.debug.js.map +1 -1
- package/dist/tiny-helix.esm.debug.js +834 -314
- package/dist/tiny-helix.esm.debug.js.map +1 -1
- package/dist/tiny-helix.esm.js +1 -1
- package/dist/tiny-helix.esm.js.map +1 -1
- package/dist/tiny-helix.js +1 -1
- package/dist/tiny-helix.js.map +1 -1
- package/dist/utils/MipRenderer.d.ts +13 -0
- package/dist/utils/padArrayBuffer.d.ts +3 -1
- package/package.json +54 -54
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,95 +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.
|
|
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.
|
package/dist/BindGroup.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { WebGPUContext } from "./WebGPUContext";
|
|
3
3
|
import { UniformBuffer, UniformBufferLayout } from "./buffers/UniformBuffer";
|
|
4
4
|
import { IBuffer } from "./buffers/IBuffer";
|
|
5
|
-
import {
|
|
5
|
+
import { TextureView } from "./Texture";
|
|
6
6
|
import { Sampler } from "./Sampler";
|
|
7
7
|
import { TextureFormat } from "../dist";
|
|
8
|
-
import { StorageAccess } from "./enums";
|
|
8
|
+
import { SamplerType, StorageAccess, TextureSampleType, TextureViewDimension } from "./enums";
|
|
9
9
|
/**
|
|
10
10
|
* Lightweight wrapper around a GPUBindGroup.
|
|
11
11
|
* Use {@link TinyHelix.createBindGroup} to create instances.
|
|
@@ -43,7 +43,7 @@ export declare class BindGroupBuilder {
|
|
|
43
43
|
*/
|
|
44
44
|
withBuffer(fieldName: string, buffer: IBuffer): this;
|
|
45
45
|
/** Attach a texture to the bind group. */
|
|
46
|
-
withTexture(fieldName: string, texture:
|
|
46
|
+
withTexture(fieldName: string, texture: TextureView): this;
|
|
47
47
|
/** Attach a sampler to the bind group at the given binding index. */
|
|
48
48
|
withSampler(fieldName: string, sampler: Sampler): this;
|
|
49
49
|
/**
|
|
@@ -96,23 +96,24 @@ declare class BindGroupLayoutBuilder {
|
|
|
96
96
|
/**
|
|
97
97
|
* Add a storage buffer binding at the given index and record its layout.
|
|
98
98
|
* @param index - binding index
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
99
|
+
* @param fieldName - a name used to reference the layout later
|
|
100
|
+
* @param accessMode - Defines whether the storage buffer is read-only or not.
|
|
101
101
|
* @param visibility - shader stage visibility flags (defaults to FRAGMENT|COMPUTE)
|
|
102
102
|
*/
|
|
103
|
-
withStorageBuffer(index: number,
|
|
103
|
+
withStorageBuffer(index: number, fieldName: string, accessMode: StorageAccess, minBindingSize?: number, visibility?: GPUShaderStageFlags): this;
|
|
104
104
|
/**
|
|
105
105
|
* Add a storage texture binding at the given index. The texture will be
|
|
106
106
|
* write-only and use RGBA8Unorm format.
|
|
107
107
|
* @param index
|
|
108
|
-
* @param
|
|
108
|
+
* @param fieldName
|
|
109
109
|
* @param format
|
|
110
|
-
* @param
|
|
110
|
+
* @param accessMode
|
|
111
111
|
* @param visibility
|
|
112
|
+
* @param viewDimension
|
|
112
113
|
*/
|
|
113
|
-
withStorageTexture(index: number,
|
|
114
|
-
withTexture(index: number,
|
|
115
|
-
withSampler(index: number,
|
|
114
|
+
withStorageTexture(index: number, fieldName: string, format: TextureFormat, accessMode: StorageAccess, visibility?: GPUShaderStageFlags, viewDimension?: TextureViewDimension): this;
|
|
115
|
+
withTexture(index: number, fieldName: string, visibility?: GPUShaderStageFlags, viewDimension?: TextureViewDimension, sampleType?: TextureSampleType): this;
|
|
116
|
+
withSampler(index: number, fieldName: string, samplerType?: SamplerType, visibility?: GPUShaderStageFlags): this;
|
|
116
117
|
/**
|
|
117
118
|
* Create the underlying GPUBindGroupLayout and return a wrapped `BindGroupLayout`.
|
|
118
119
|
*/
|
|
@@ -10,8 +10,10 @@ export declare class ComputePipelineBuilder {
|
|
|
10
10
|
private _label?;
|
|
11
11
|
private _shader;
|
|
12
12
|
private _entry;
|
|
13
|
+
private _overrideConstants;
|
|
13
14
|
constructor(ctx: WebGPUContext);
|
|
14
15
|
withLabel(label: string): this;
|
|
16
|
+
withOverrideConstant(id: string, value: number): this;
|
|
15
17
|
/** Select the shader entry point for the fragment stage. */
|
|
16
18
|
withShader(shader: Shader, entry: string): this;
|
|
17
19
|
build(): ComputePipeline;
|
package/dist/Mesh.d.ts
CHANGED
|
@@ -144,7 +144,7 @@ export declare class StreamBuilder {
|
|
|
144
144
|
* Upload vertex data for this stream. `keepOnCPU` controls whether the
|
|
145
145
|
* source ArrayBuffer is retained in memory for readback.
|
|
146
146
|
*/
|
|
147
|
-
withData(data: ArrayBufferLike, keepOnCPU?: boolean): void;
|
|
147
|
+
withData(data: ArrayBufferLike, byteOffset?: number, byteLength?: number, keepOnCPU?: boolean): void;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Fluent builder for creating a Mesh. Use `pushStream()` to describe vertex
|
package/dist/RenderPass.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { RenderPipeline } from "./RenderPipeline";
|
|
|
4
4
|
import { Mesh } from "./Mesh";
|
|
5
5
|
import { BindGroup } from "./BindGroup";
|
|
6
6
|
import { IndexedCollection } from "./utils/IndexedCollection";
|
|
7
|
+
import { StoreOp } from "./enums";
|
|
8
|
+
import { Buffer } from "./buffers/Buffer";
|
|
7
9
|
/**
|
|
8
10
|
* Lightweight wrapper around GPURenderPassEncoder. Provides a minimal API
|
|
9
11
|
* for ending the pass; higher-level helpers may be added later.
|
|
@@ -37,7 +39,13 @@ export declare class RenderPass {
|
|
|
37
39
|
/**
|
|
38
40
|
* Issue a draw call using the currently set pipeline and mesh.
|
|
39
41
|
*/
|
|
40
|
-
draw(): this;
|
|
42
|
+
draw(numInstances?: number): this;
|
|
43
|
+
/**
|
|
44
|
+
* Issue an indirect draw call using the currently set pipeline and mesh.
|
|
45
|
+
* @param indirectBuffer A Buffer containing the draw parameters. The buffer must have been created with the `Indirect` usage flag.
|
|
46
|
+
* @param indirectOffset The offset in bytes into the indirectBuffer where the draw parameters are stored. Must be a multiple of 4.
|
|
47
|
+
*/
|
|
48
|
+
drawIndirect(indirectBuffer: Buffer, indirectOffset?: number): this;
|
|
41
49
|
/**
|
|
42
50
|
* End the render pass. After calling end(), the underlying encoder may
|
|
43
51
|
* continue recording other passes or be finished/submitted.
|
|
@@ -61,6 +69,7 @@ export declare class RenderPassBuilder {
|
|
|
61
69
|
private _clearDepth?;
|
|
62
70
|
private _clearStencil?;
|
|
63
71
|
private _globalBindGroups;
|
|
72
|
+
private _storeOps;
|
|
64
73
|
/**
|
|
65
74
|
* Create a new builder instance. This should only be called from the CommandEncoder
|
|
66
75
|
* instance (see {@link CommandEncoder.createRenderPass}).
|
|
@@ -80,11 +89,17 @@ export declare class RenderPassBuilder {
|
|
|
80
89
|
/**
|
|
81
90
|
* Set the clear color for the most recently added color target.
|
|
82
91
|
* Overloads allow passing an array or individual color components.
|
|
92
|
+
* Be sure to call this unless you really want to load the existing contents of the target.
|
|
83
93
|
*/
|
|
84
94
|
withClearColor(): this;
|
|
85
95
|
withClearColor(r: number[] | IndexedCollection): this;
|
|
86
96
|
withClearColor(r: number, g: number, b: number): this;
|
|
87
97
|
withClearColor(r: number, g: number, b: number, a: number): this;
|
|
98
|
+
/**
|
|
99
|
+
* Set the store operation for the most recently added color target. Defaults to 'store' if not specified.
|
|
100
|
+
* @param storeOp
|
|
101
|
+
*/
|
|
102
|
+
withStoreOp(storeOp: StoreOp): this;
|
|
88
103
|
/**
|
|
89
104
|
* Set the clear stencil value
|
|
90
105
|
*/
|
package/dist/RenderPipeline.d.ts
CHANGED
|
@@ -59,15 +59,27 @@ export declare class RenderPipelineBuilder {
|
|
|
59
59
|
* @param compare
|
|
60
60
|
*/
|
|
61
61
|
withDepthCompare(compare: CompareFunction): this;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the depth bias for each triangle.
|
|
64
|
+
* @param depthBias Constant depth bias added to each triangle fragment.
|
|
65
|
+
* @param slopeScale Depth bias that scales with the triangle fragment’s slope.
|
|
66
|
+
* @param max The maximum depth bias of a triangle fragment.
|
|
67
|
+
*/
|
|
68
|
+
withDepthBias(depthBias: number, slopeScale?: number, max?: number): this;
|
|
62
69
|
/**
|
|
63
70
|
* Enable or disable depth writes. Default is `true`.
|
|
64
71
|
* @param enabled
|
|
65
72
|
*/
|
|
66
73
|
withDepthWrite(enabled: boolean): this;
|
|
67
|
-
/**
|
|
68
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Override a shader constant for specialization. We do NOT use `ShaderStage.Vertex | ShaderStage.Fragment` as
|
|
76
|
+
* default because some browser implementations (as of early 2026) have bugs when a non-existent constant is defined
|
|
77
|
+
*/
|
|
78
|
+
withOverrideConstant(id: string, value: number, pipeline: GPUShaderStageFlags): this;
|
|
69
79
|
/** Set the blend mode for the last assigned (or default) color target. */
|
|
70
80
|
withBlendMode(blendMode: BlendMode): this;
|
|
81
|
+
/** Set the color write mask for the last assigned (or default) color target. */
|
|
82
|
+
withColorWrite(r: boolean, g?: boolean, b?: boolean, a?: boolean): this;
|
|
71
83
|
/**
|
|
72
84
|
* Build and create the `RenderPipeline`. Throws if required pieces (shader/vertices)
|
|
73
85
|
* are missing.
|
package/dist/Sampler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@webgpu/types" />
|
|
2
2
|
import { WebGPUContext } from "./WebGPUContext";
|
|
3
|
-
import { AddressMode, FilterMode } from "./enums";
|
|
3
|
+
import { AddressMode, CompareFunction, FilterMode } from "./enums";
|
|
4
4
|
export declare class Sampler {
|
|
5
5
|
readonly _inner: GPUSampler;
|
|
6
6
|
private static DEFAULT_TRILINEAR;
|
|
@@ -8,17 +8,9 @@ export declare class Sampler {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class SamplerBuilder {
|
|
10
10
|
private _ctx;
|
|
11
|
-
private
|
|
12
|
-
private _addressModeV?;
|
|
13
|
-
private _addressModeW?;
|
|
14
|
-
private _minFilter?;
|
|
15
|
-
private _magFilter?;
|
|
16
|
-
private _mipmapFilter?;
|
|
17
|
-
private _minMipLevel?;
|
|
18
|
-
private _maxMipLevel?;
|
|
19
|
-
private _maxAnisotropy?;
|
|
20
|
-
private _compare?;
|
|
11
|
+
private _desc;
|
|
21
12
|
constructor(ctx: WebGPUContext);
|
|
13
|
+
withLabel(label: string): this;
|
|
22
14
|
withAddressMode(u: AddressMode, v?: AddressMode, w?: AddressMode): this;
|
|
23
15
|
withFiltering(minFilter: FilterMode, magFilter?: FilterMode, mipmapFilter?: FilterMode): this;
|
|
24
16
|
withTrilinearFiltering(): this;
|
|
@@ -26,6 +18,6 @@ export declare class SamplerBuilder {
|
|
|
26
18
|
withAnisotropicFiltering(maxAnisotropy: number): this;
|
|
27
19
|
withMinMipLevel(level: number): this;
|
|
28
20
|
withMaxMipLevel(level: number): this;
|
|
29
|
-
withCompareFunction(compare:
|
|
21
|
+
withCompareFunction(compare: CompareFunction): this;
|
|
30
22
|
build(): Sampler;
|
|
31
23
|
}
|
package/dist/Shader.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class Shader {
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
constructor(inner: GPUShaderModule, ctx: WebGPUContext, vertexAttributes: AttributeMap, bindGroupLayouts?: BindGroupLayout[]);
|
|
20
|
+
getCompilationInfo(): Promise<GPUCompilationInfo>;
|
|
20
21
|
/**
|
|
21
22
|
* Get the shader location for a named vertex attribute. Returns undefined if the attribute
|
|
22
23
|
* is not declared by the shader.
|
|
@@ -64,7 +65,7 @@ export declare class ShaderBuilder {
|
|
|
64
65
|
*/
|
|
65
66
|
withInclude(name: string, code: string): this;
|
|
66
67
|
/** Declare a named vertex attribute and the location it maps to in the shader. */
|
|
67
|
-
withVertexAttribute(
|
|
68
|
+
withVertexAttribute(location: number, name: string): this;
|
|
68
69
|
/**
|
|
69
70
|
* Declare a bind group layout used by this shader. The provided builder
|
|
70
71
|
* callback is used to construct the layout description.
|
package/dist/Texture.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@webgpu/types" />
|
|
2
2
|
import { WebGPUContext } from "./WebGPUContext";
|
|
3
|
-
import { TextureFormat } from "./enums";
|
|
3
|
+
import { TextureDimension, TextureFormat, TextureViewDimension } from "./enums";
|
|
4
4
|
import { IBuffer } from "./buffers/IBuffer";
|
|
5
5
|
import { TextureUsage } from "./buffers/Buffer";
|
|
6
6
|
/**
|
|
@@ -11,27 +11,43 @@ export declare class Texture implements IBuffer {
|
|
|
11
11
|
/** @internal */
|
|
12
12
|
readonly _inner: GPUTexture;
|
|
13
13
|
private _format;
|
|
14
|
+
private _ctx;
|
|
15
|
+
private _mipper?;
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param texture - The underlying GPUTexture
|
|
17
|
+
* @internal
|
|
17
18
|
*/
|
|
18
|
-
static from_webgpu(texture: GPUTexture, format: TextureFormat): Texture;
|
|
19
|
-
constructor(inner: GPUTexture, format: TextureFormat);
|
|
19
|
+
static from_webgpu(texture: GPUTexture, format: TextureFormat, ctx: WebGPUContext, mipShader?: GPUShaderModule): Texture;
|
|
20
|
+
constructor(inner: GPUTexture, format: TextureFormat, ctx: WebGPUContext, mipShader?: GPUShaderModule);
|
|
20
21
|
createView(): TextureViewBuilder;
|
|
21
22
|
get format(): TextureFormat;
|
|
23
|
+
get mipLevelCount(): number;
|
|
24
|
+
get width(): number;
|
|
25
|
+
get height(): number;
|
|
26
|
+
get depthOrArrayLayers(): number;
|
|
22
27
|
_getBufferResource(): GPUBindingResource;
|
|
28
|
+
uploadImage(data: ImageBitmap, mipLevel?: number): void;
|
|
29
|
+
uploadData(data: GPUAllowSharedBufferSource, mipLevel?: number): void;
|
|
30
|
+
generateMipmaps(): void;
|
|
31
|
+
dimension(): TextureDimension;
|
|
23
32
|
}
|
|
24
33
|
export declare class TextureBuilder {
|
|
25
34
|
private _ctx;
|
|
26
35
|
private _size;
|
|
27
|
-
private _data
|
|
36
|
+
private _data?;
|
|
28
37
|
private _format;
|
|
29
38
|
private _usage;
|
|
30
|
-
|
|
39
|
+
private _dimension;
|
|
40
|
+
private _mipLevelCount;
|
|
41
|
+
private _generateMips;
|
|
42
|
+
private _mipShader;
|
|
43
|
+
constructor(ctx: WebGPUContext, mipShader: GPUShaderModule);
|
|
31
44
|
withSize(width: number, height: number, depthOrArrayLayers?: number): this;
|
|
32
|
-
|
|
45
|
+
withDimension(dim: TextureDimension): this;
|
|
46
|
+
withMipLevels(count?: number): this;
|
|
33
47
|
withFormat(format: TextureFormat): this;
|
|
34
|
-
|
|
48
|
+
withData(data: GPUAllowSharedBufferSource, mipLevel?: number): this;
|
|
49
|
+
withImage(data: ImageBitmap, mipLevel?: number): this;
|
|
50
|
+
withGeneratedMipmaps(): this;
|
|
35
51
|
withUsage(usage: TextureUsage): this;
|
|
36
52
|
build(): Texture;
|
|
37
53
|
}
|
|
@@ -47,9 +63,22 @@ export declare class TextureViewBuilder {
|
|
|
47
63
|
* @internal
|
|
48
64
|
*/
|
|
49
65
|
constructor(texture: Texture);
|
|
66
|
+
withUsage(usage: TextureUsage): this;
|
|
50
67
|
withSingleMip(level: number): this;
|
|
51
68
|
withMipRange(start: number, end: number): this;
|
|
52
69
|
withSingleLayer(layer: number): this;
|
|
53
70
|
withLayerRange(start: number, end: number): this;
|
|
71
|
+
withDimension(dim: TextureViewDimension): this;
|
|
54
72
|
build(): TextureView;
|
|
55
73
|
}
|
|
74
|
+
export declare class TextureUtils {
|
|
75
|
+
static isBc(format: TextureFormat): boolean;
|
|
76
|
+
static isEtc(format: TextureFormat): boolean;
|
|
77
|
+
static getBlockWidth(format: TextureFormat): number;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the number of bytes in a compressed or uncompressed block for the
|
|
80
|
+
* given texture format. Matches the mapping from the Rust implementation and
|
|
81
|
+
* throws for unsupported formats.
|
|
82
|
+
*/
|
|
83
|
+
static bytesPerBlock(format: TextureFormat): number;
|
|
84
|
+
}
|
package/dist/TinyHelix.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
1
2
|
import { WebGPUContextOptions } from './WebGPUContext';
|
|
2
3
|
import { CommandEncoder } from "./CommandEncoder";
|
|
3
4
|
import { Texture, TextureBuilder } from "./Texture";
|
|
@@ -23,6 +24,7 @@ export interface TinyHelixOptions extends WebGPUContextOptions {
|
|
|
23
24
|
* backbuffer and provides helpers to create render targets and command encoders.
|
|
24
25
|
*/
|
|
25
26
|
export declare class TinyHelix {
|
|
27
|
+
private _parent;
|
|
26
28
|
private _context;
|
|
27
29
|
private _options;
|
|
28
30
|
private _backbuffer?;
|
|
@@ -31,12 +33,30 @@ export declare class TinyHelix {
|
|
|
31
33
|
private _depthStencilTarget?;
|
|
32
34
|
private _shaderIncludes;
|
|
33
35
|
private _canvas;
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
private _globalBindGroupLayouts;
|
|
37
|
+
private _globalBindGroups;
|
|
38
|
+
private _mipShader;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new TinyHelix instance from a HTMLCanvasElement or an existing TinyHelix instance.
|
|
41
|
+
* When creating from a Canvas, call `initialize()` before rendering to initialize the WebGPU context. When
|
|
42
|
+
* using an existing TinyHelix instance, the new instance will share the same WebGPU context and resources.
|
|
43
|
+
*/
|
|
44
|
+
constructor(canvasOrHX: HTMLCanvasElement | TinyHelix);
|
|
45
|
+
get shaderF16Supported(): boolean;
|
|
46
|
+
get floatFilteringSupported(): boolean;
|
|
47
|
+
get adapter(): GPUAdapter;
|
|
48
|
+
get device(): GPUDevice;
|
|
49
|
+
get context(): GPUCanvasContext;
|
|
50
|
+
/**
|
|
51
|
+
* Copies all shader includes from another TinyHelix instance.
|
|
52
|
+
* @param hx - The TinyHelix instance to copy includes from.
|
|
53
|
+
*/
|
|
54
|
+
copyIncludesFrom(hx: TinyHelix): this;
|
|
55
|
+
/**
|
|
56
|
+
* Copies all global bind groups from another TinyHelix instance.
|
|
57
|
+
* @param hx - The TinyHelix instance to copy global bind groups from.
|
|
58
|
+
*/
|
|
59
|
+
copyGlobalBindGroupsFrom(hx: TinyHelix): this;
|
|
40
60
|
/**
|
|
41
61
|
* Initializes the underlying WebGPU context and prepares resources.
|
|
42
62
|
* @param options - Configuration options forwarded to the WebGPU context
|
package/dist/WebGPUContext.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export declare class WebGPUContext {
|
|
|
24
24
|
private _format;
|
|
25
25
|
private _canvas;
|
|
26
26
|
private _colorSpace;
|
|
27
|
+
private _shaderF16Supported;
|
|
28
|
+
private _floatFilteringSupported;
|
|
27
29
|
/**
|
|
28
30
|
* Gets the WebGPU adapter. Throws if not initialized.
|
|
29
31
|
*/
|
|
@@ -58,6 +60,15 @@ export declare class WebGPUContext {
|
|
|
58
60
|
* @throws Error if WebGPU is not supported or initialization fails
|
|
59
61
|
*/
|
|
60
62
|
initialize(options?: WebGPUContextOptions): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Indicates whether the shaders support the f16 format. Use the type `half`, `vec2h`, `vec3h`, `vec4h`, etc. to
|
|
65
|
+
* provide f32 fallbacks if f16 is not supported.
|
|
66
|
+
*/
|
|
67
|
+
get shaderF16Supported(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Indicates whether the device supports filtering on float32 textures.
|
|
70
|
+
*/
|
|
71
|
+
get floatFilteringSupported(): boolean;
|
|
61
72
|
/**
|
|
62
73
|
* Internal helper to fetch the current swapchain texture.
|
|
63
74
|
* @internal
|
package/dist/buffers/Buffer.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare class BufferBuilder {
|
|
|
39
39
|
private _size;
|
|
40
40
|
private _keepData;
|
|
41
41
|
private _usage;
|
|
42
|
+
private _dataOffset;
|
|
42
43
|
constructor(ctx: WebGPUContext);
|
|
43
44
|
/**
|
|
44
45
|
* Add usage flags for the GPU buffer.
|
|
@@ -49,7 +50,7 @@ export declare class BufferBuilder {
|
|
|
49
50
|
* ArrayBuffer is stored in the resulting `Buffer.data` field for readback or
|
|
50
51
|
* reuse.
|
|
51
52
|
*/
|
|
52
|
-
withData(data: ArrayBufferLike, keepOnCPU?: boolean): this;
|
|
53
|
+
withData(data: ArrayBufferLike, keepOnCPU?: boolean, offset?: number, length?: number): this;
|
|
53
54
|
/**
|
|
54
55
|
* Specify a size for the buffer, used when not providing data.
|
|
55
56
|
*/
|
package/dist/enums.d.ts
CHANGED
|
@@ -156,3 +156,42 @@ export declare enum StorageAccess {
|
|
|
156
156
|
Read = "read-only",
|
|
157
157
|
Write = "write-only"
|
|
158
158
|
}
|
|
159
|
+
export declare enum TextureSampleType {
|
|
160
|
+
Float = "float",
|
|
161
|
+
Sint = "sint",
|
|
162
|
+
Uint = "uint",
|
|
163
|
+
UnfilterableFloat = "unfilterable-float",
|
|
164
|
+
Depth = "depth"
|
|
165
|
+
}
|
|
166
|
+
export declare enum SamplerType {
|
|
167
|
+
Filtering = "filtering",
|
|
168
|
+
NonFiltering = "non-filtering",
|
|
169
|
+
Comparison = "comparison"
|
|
170
|
+
}
|
|
171
|
+
export declare enum ColorChannel {
|
|
172
|
+
Red,
|
|
173
|
+
Green,
|
|
174
|
+
Blue
|
|
175
|
+
}
|
|
176
|
+
export declare enum TextureDimension {
|
|
177
|
+
D1 = "1d",
|
|
178
|
+
D2 = "2d",
|
|
179
|
+
D3 = "3d"
|
|
180
|
+
}
|
|
181
|
+
export declare enum TextureViewDimension {
|
|
182
|
+
D1 = "1d",
|
|
183
|
+
D2 = "2d",
|
|
184
|
+
D2Array = "2d-array",
|
|
185
|
+
Cube = "cube",
|
|
186
|
+
CubeArray = "cube-array",
|
|
187
|
+
D3 = "3d"
|
|
188
|
+
}
|
|
189
|
+
export declare enum ShaderStage {
|
|
190
|
+
Vertex,
|
|
191
|
+
Fragment,
|
|
192
|
+
Compute
|
|
193
|
+
}
|
|
194
|
+
export declare enum StoreOp {
|
|
195
|
+
Store = "store",
|
|
196
|
+
Discard = "discard"
|
|
197
|
+
}
|