@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.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/BindGroup.d.ts +121 -0
- package/dist/BlendMode.d.ts +21 -0
- package/dist/Buffer.d.ts +66 -0
- package/dist/BufferDataWriter.d.ts +67 -0
- package/dist/CommandEncoder.d.ts +50 -0
- package/dist/ComputePass.d.ts +37 -0
- package/dist/ComputePipeline.d.ts +18 -0
- package/dist/Mesh.d.ts +177 -0
- package/dist/Pipeline.d.ts +47 -0
- package/dist/RenderPass.d.ts +101 -0
- package/dist/RenderPipeline.d.ts +77 -0
- package/dist/RenderTarget.d.ts +44 -0
- package/dist/Renderer.d.ts +44 -0
- package/dist/Sampler.d.ts +31 -0
- package/dist/Shader.d.ts +77 -0
- package/dist/Texture.d.ts +55 -0
- package/dist/TinyHelix.d.ts +163 -0
- package/dist/UniformBuffer.d.ts +84 -0
- package/dist/WebGPUContext.d.ts +70 -0
- package/dist/buffers/Buffer.d.ts +79 -0
- package/dist/buffers/BufferDataWriter.d.ts +68 -0
- package/dist/buffers/IBuffer.d.ts +4 -0
- package/dist/buffers/UniformBuffer.d.ts +111 -0
- package/dist/enums.d.ts +158 -0
- package/dist/index.d.ts +24 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/tiny-helix.debug.js +3351 -0
- package/dist/tiny-helix.debug.js.map +1 -0
- package/dist/tiny-helix.esm.debug.js +3386 -0
- package/dist/tiny-helix.esm.debug.js.map +1 -0
- package/dist/tiny-helix.esm.js +2 -0
- package/dist/tiny-helix.esm.js.map +1 -0
- package/dist/tiny-helix.js +2 -0
- package/dist/tiny-helix.js.map +1 -0
- package/dist/utils/IndexedCollection.d.ts +4 -0
- package/dist/utils/float32ToFloat16.d.ts +5 -0
- package/dist/utils/mapUndefined.d.ts +6 -0
- package/dist/utils/padArrayBuffer.d.ts +10 -0
- package/package.json +54 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { WebGPUContext } from './WebGPUContext';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a render pipeline
|
|
4
|
+
*/
|
|
5
|
+
export interface PipelineOptions {
|
|
6
|
+
/** Vertex shader WGSL code */
|
|
7
|
+
vertexShader: string;
|
|
8
|
+
/** Fragment shader WGSL code */
|
|
9
|
+
fragmentShader: string;
|
|
10
|
+
/** Vertex buffer layouts */
|
|
11
|
+
vertexBufferLayouts?: GPUVertexBufferLayout[];
|
|
12
|
+
/** Primitive topology (default: 'triangle-list') */
|
|
13
|
+
topology?: GPUPrimitiveTopology;
|
|
14
|
+
/** Bind group layouts for the pipeline */
|
|
15
|
+
bindGroupLayouts?: GPUBindGroupLayout[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wrapper for WebGPU render pipeline creation and management
|
|
19
|
+
*/
|
|
20
|
+
export declare class Pipeline {
|
|
21
|
+
private _context;
|
|
22
|
+
private _pipeline;
|
|
23
|
+
private _layout;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new Pipeline instance
|
|
26
|
+
* @param context - The WebGPU context to use
|
|
27
|
+
*/
|
|
28
|
+
constructor(context: WebGPUContext);
|
|
29
|
+
/**
|
|
30
|
+
* Gets the underlying WebGPU render pipeline
|
|
31
|
+
*/
|
|
32
|
+
get pipeline(): GPURenderPipeline | null;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the pipeline layout
|
|
35
|
+
*/
|
|
36
|
+
get layout(): GPUPipelineLayout | null;
|
|
37
|
+
/**
|
|
38
|
+
* Creates the render pipeline
|
|
39
|
+
* @param options - Pipeline configuration options
|
|
40
|
+
* @throws Error if device is not initialized
|
|
41
|
+
*/
|
|
42
|
+
create(options: PipelineOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Destroys the pipeline and releases resources
|
|
45
|
+
*/
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { RenderTarget } from "./RenderTarget";
|
|
3
|
+
import { RenderPipeline } from "./RenderPipeline";
|
|
4
|
+
import { Mesh } from "./Mesh";
|
|
5
|
+
import { BindGroup } from "./BindGroup";
|
|
6
|
+
import { IndexedCollection } from "./utils/IndexedCollection";
|
|
7
|
+
/**
|
|
8
|
+
* Lightweight wrapper around GPURenderPassEncoder. Provides a minimal API
|
|
9
|
+
* for ending the pass; higher-level helpers may be added later.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RenderPass {
|
|
12
|
+
private readonly _inner;
|
|
13
|
+
private _renderPipeline?;
|
|
14
|
+
private _numVertices;
|
|
15
|
+
private _numIndices;
|
|
16
|
+
/**
|
|
17
|
+
* Internal accessor for the underlying GPURenderPassEncoder. Not intended for public use.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
constructor(inner: GPURenderPassEncoder);
|
|
21
|
+
/**
|
|
22
|
+
* Set the render pipeline to use for the next draw calls.
|
|
23
|
+
* @param pipeline
|
|
24
|
+
*/
|
|
25
|
+
setPipeline(pipeline: RenderPipeline): this;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the mesh to use for the next draw calls.
|
|
28
|
+
* @param mesh
|
|
29
|
+
*/
|
|
30
|
+
setMesh(mesh: Mesh): this;
|
|
31
|
+
/**
|
|
32
|
+
* Set a bind group at the given index.
|
|
33
|
+
* @param index - bind group index in the render pipeline layout
|
|
34
|
+
* @param bindGroup - a `BindGroup` instance
|
|
35
|
+
*/
|
|
36
|
+
setBindGroup(index: number, bindGroup: BindGroup): this;
|
|
37
|
+
/**
|
|
38
|
+
* Issue a draw call using the currently set pipeline and mesh.
|
|
39
|
+
*/
|
|
40
|
+
draw(): this;
|
|
41
|
+
/**
|
|
42
|
+
* End the render pass. After calling end(), the underlying encoder may
|
|
43
|
+
* continue recording other passes or be finished/submitted.
|
|
44
|
+
*/
|
|
45
|
+
end(): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fluent builder for configuring and creating a render pass.
|
|
49
|
+
*
|
|
50
|
+
* Use the builder to specify color targets, clear values and labels before
|
|
51
|
+
* calling `build()` to obtain a `RenderPass` instance.
|
|
52
|
+
*/
|
|
53
|
+
export declare class RenderPassBuilder {
|
|
54
|
+
private _encoder;
|
|
55
|
+
private _label?;
|
|
56
|
+
private _colorTargets;
|
|
57
|
+
private _clearColors;
|
|
58
|
+
private _defaultTarget;
|
|
59
|
+
private _defaultDepthTarget?;
|
|
60
|
+
private _depthTarget?;
|
|
61
|
+
private _clearDepth?;
|
|
62
|
+
private _clearStencil?;
|
|
63
|
+
private _globalBindGroups;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new builder instance. This should only be called from the CommandEncoder
|
|
66
|
+
* instance (see {@link CommandEncoder.createRenderPass}).
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
constructor(commandEncoder: GPUCommandEncoder, globalBindGroups: BindGroup[], defaultTarget: RenderTarget, defaultDepthTarget?: RenderTarget);
|
|
70
|
+
/**
|
|
71
|
+
* Assign a human-readable label for the render pass (useful for GPU debuggers).
|
|
72
|
+
*/
|
|
73
|
+
withLabel(label: string): this;
|
|
74
|
+
/**
|
|
75
|
+
* Add a color target to render into. If no targets are added the default
|
|
76
|
+
* backbuffer target will be used.
|
|
77
|
+
*/
|
|
78
|
+
withColorTarget(target: RenderTarget): this;
|
|
79
|
+
withDepthStencilTarget(target: RenderTarget): this;
|
|
80
|
+
/**
|
|
81
|
+
* Set the clear color for the most recently added color target.
|
|
82
|
+
* Overloads allow passing an array or individual color components.
|
|
83
|
+
*/
|
|
84
|
+
withClearColor(): this;
|
|
85
|
+
withClearColor(r: number[] | IndexedCollection): this;
|
|
86
|
+
withClearColor(r: number, g: number, b: number): this;
|
|
87
|
+
withClearColor(r: number, g: number, b: number, a: number): this;
|
|
88
|
+
/**
|
|
89
|
+
* Set the clear stencil value
|
|
90
|
+
*/
|
|
91
|
+
withClearStencil(stencil: number): this;
|
|
92
|
+
/**
|
|
93
|
+
* Set the clear depth value
|
|
94
|
+
*/
|
|
95
|
+
withClearDepth(depth: number): this;
|
|
96
|
+
/**
|
|
97
|
+
* Build and begin the render pass. Returns a `RenderPass` wrapper around
|
|
98
|
+
* the low-level GPURenderPassEncoder.
|
|
99
|
+
*/
|
|
100
|
+
build(): RenderPass;
|
|
101
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { Shader } from "./Shader";
|
|
3
|
+
import { WebGPUContext } from "./WebGPUContext";
|
|
4
|
+
import { Mesh } from "./Mesh";
|
|
5
|
+
import { CompareFunction, CullMode, TextureFormat } from "./enums";
|
|
6
|
+
import { BlendMode } from "./BlendMode";
|
|
7
|
+
/**
|
|
8
|
+
* Thin wrapper around GPURenderPipeline exposing a small helper for attribute
|
|
9
|
+
* location lookup. The underlying pipeline and shader are available for advanced use.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RenderPipeline {
|
|
12
|
+
/** @internal */
|
|
13
|
+
readonly _inner: GPURenderPipeline;
|
|
14
|
+
private _shader;
|
|
15
|
+
constructor(inner: GPURenderPipeline, shader: Shader);
|
|
16
|
+
/**
|
|
17
|
+
* Helper to get the shader-declared attribute location for a named attribute.
|
|
18
|
+
*/
|
|
19
|
+
getVertexAttributeLocation(name: string): number | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Fluent builder for creating a GPURenderPipeline. Attach a `Shader` and
|
|
23
|
+
* optionally a `Mesh` (to derive vertex buffer layouts) before calling `build()`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class RenderPipelineBuilder {
|
|
26
|
+
private _ctx;
|
|
27
|
+
private _shader?;
|
|
28
|
+
private _colorTargets;
|
|
29
|
+
private _defaultColorState;
|
|
30
|
+
private _depthState?;
|
|
31
|
+
private _defaultDepthState?;
|
|
32
|
+
private _vertexEntry;
|
|
33
|
+
private _fragmentEntry;
|
|
34
|
+
private _label;
|
|
35
|
+
private _overrideConstants;
|
|
36
|
+
private _cullMode;
|
|
37
|
+
private _mesh;
|
|
38
|
+
constructor(ctx: WebGPUContext, defaultDepthFormat?: TextureFormat);
|
|
39
|
+
/** Assign a human-readable label for the pipeline (useful in graphics debuggers). */
|
|
40
|
+
withLabel(label: string): this;
|
|
41
|
+
/** Set face-culling mode. Default is `Back`. */
|
|
42
|
+
withCullMode(value: CullMode): this;
|
|
43
|
+
/** Provide a Mesh to automatically derive vertex buffer layouts. */
|
|
44
|
+
withMesh(mesh: Mesh): this;
|
|
45
|
+
/** Attach a compiled Shader to the pipeline. */
|
|
46
|
+
withShader(shader: Shader): this;
|
|
47
|
+
/** Select the shader entry point for the vertex stage. */
|
|
48
|
+
withVertexShader(entry: string): this;
|
|
49
|
+
/** Select the shader entry point for the fragment stage. */
|
|
50
|
+
withFragmentShader(entry: string): this;
|
|
51
|
+
/** Add a color target with the given texture format. */
|
|
52
|
+
withColorTarget(format: TextureFormat): this;
|
|
53
|
+
/**
|
|
54
|
+
* Add a depth target with the given texture format.
|
|
55
|
+
*/
|
|
56
|
+
withDepthTarget(format: TextureFormat): this;
|
|
57
|
+
/**
|
|
58
|
+
* Set the depth compare function. Default is `less`.
|
|
59
|
+
* @param compare
|
|
60
|
+
*/
|
|
61
|
+
withDepthCompare(compare: CompareFunction): this;
|
|
62
|
+
/**
|
|
63
|
+
* Enable or disable depth writes. Default is `true`.
|
|
64
|
+
* @param enabled
|
|
65
|
+
*/
|
|
66
|
+
withDepthWrite(enabled: boolean): this;
|
|
67
|
+
/** Override a shader constant for specialization. */
|
|
68
|
+
withOverrideConstant(id: string, value: number): this;
|
|
69
|
+
/** Set the blend mode for the last assigned (or default) color target. */
|
|
70
|
+
withBlendMode(blendMode: BlendMode): this;
|
|
71
|
+
/**
|
|
72
|
+
* Build and create the `RenderPipeline`. Throws if required pieces (shader/vertices)
|
|
73
|
+
* are missing.
|
|
74
|
+
*/
|
|
75
|
+
build(): RenderPipeline;
|
|
76
|
+
private get lastColorTarget();
|
|
77
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { Texture } from "./Texture";
|
|
3
|
+
import { TextureFormat } from "./enums";
|
|
4
|
+
/**
|
|
5
|
+
* Lightweight wrapper around a GPUTextureView representing a render target.
|
|
6
|
+
* Use `view()` to get the underlying GPUTextureView when building render passes.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RenderTarget {
|
|
9
|
+
readonly _inner: GPUTextureView;
|
|
10
|
+
private _format;
|
|
11
|
+
constructor(view: GPUTextureView, format: TextureFormat);
|
|
12
|
+
get format(): TextureFormat;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builder for creating a `RenderTarget` from a `Texture`.
|
|
16
|
+
*
|
|
17
|
+
* The builder produces a GPUTextureView configured with a sensible default
|
|
18
|
+
* descriptor and wraps it in a `RenderTarget` helper.
|
|
19
|
+
*/
|
|
20
|
+
export declare class RenderTargetBuilder {
|
|
21
|
+
private _texture;
|
|
22
|
+
private _baseMipLevel;
|
|
23
|
+
private _baseArrayLayer;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new RenderTargetBuilder for the given texture. This should only be called
|
|
26
|
+
* from the TinyHelix instance (see {@link TinyHelix.createRenderTarget}).
|
|
27
|
+
* @param texture
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
constructor(texture: Texture);
|
|
32
|
+
/**
|
|
33
|
+
* Set the base mip level to use for the render target. Defaults to 0.
|
|
34
|
+
*/
|
|
35
|
+
withMipLevel(level: number): this;
|
|
36
|
+
/**
|
|
37
|
+
* Set the base array layer to use for the render target. Defaults to 0.
|
|
38
|
+
*/
|
|
39
|
+
withArrayLayer(layer: number): this;
|
|
40
|
+
/**
|
|
41
|
+
* Create and return a new `RenderTarget` instance.
|
|
42
|
+
*/
|
|
43
|
+
build(): RenderTarget;
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { WebGPUContext } from './WebGPUContext';
|
|
2
|
+
/**
|
|
3
|
+
* Basic WebGPU renderer for managing render passes
|
|
4
|
+
*/
|
|
5
|
+
export declare class Renderer {
|
|
6
|
+
private _context;
|
|
7
|
+
private _clearColor;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new Renderer instance
|
|
10
|
+
* @param context - The WebGPU context to render with
|
|
11
|
+
*/
|
|
12
|
+
constructor(context: WebGPUContext);
|
|
13
|
+
/**
|
|
14
|
+
* Gets the WebGPU context
|
|
15
|
+
*/
|
|
16
|
+
get context(): WebGPUContext;
|
|
17
|
+
/**
|
|
18
|
+
* Gets or sets the clear color
|
|
19
|
+
*/
|
|
20
|
+
get clearColor(): GPUColor;
|
|
21
|
+
set clearColor(color: GPUColor);
|
|
22
|
+
/**
|
|
23
|
+
* Begins a new render frame and returns a command encoder
|
|
24
|
+
* @returns The command encoder for this frame
|
|
25
|
+
* @throws Error if device or context is not available
|
|
26
|
+
*/
|
|
27
|
+
beginFrame(): GPUCommandEncoder;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a render pass for the current frame
|
|
30
|
+
* @param commandEncoder - The command encoder to use
|
|
31
|
+
* @returns The render pass encoder
|
|
32
|
+
* @throws Error if context is not configured
|
|
33
|
+
*/
|
|
34
|
+
beginRenderPass(commandEncoder: GPUCommandEncoder): GPURenderPassEncoder;
|
|
35
|
+
/**
|
|
36
|
+
* Ends the current frame and submits commands
|
|
37
|
+
* @param commandEncoder - The command encoder to submit
|
|
38
|
+
*/
|
|
39
|
+
endFrame(commandEncoder: GPUCommandEncoder): void;
|
|
40
|
+
/**
|
|
41
|
+
* Clears the canvas with the current clear color
|
|
42
|
+
*/
|
|
43
|
+
clear(): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { WebGPUContext } from "./WebGPUContext";
|
|
3
|
+
import { AddressMode, FilterMode } from "./enums";
|
|
4
|
+
export declare class Sampler {
|
|
5
|
+
readonly _inner: GPUSampler;
|
|
6
|
+
private static DEFAULT_TRILINEAR;
|
|
7
|
+
constructor(inner: GPUSampler);
|
|
8
|
+
}
|
|
9
|
+
export declare class SamplerBuilder {
|
|
10
|
+
private _ctx;
|
|
11
|
+
private _addressModeU?;
|
|
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?;
|
|
21
|
+
constructor(ctx: WebGPUContext);
|
|
22
|
+
withAddressMode(u: AddressMode, v?: AddressMode, w?: AddressMode): this;
|
|
23
|
+
withFiltering(minFilter: FilterMode, magFilter?: FilterMode, mipmapFilter?: FilterMode): this;
|
|
24
|
+
withTrilinearFiltering(): this;
|
|
25
|
+
withNearestFiltering(): this;
|
|
26
|
+
withAnisotropicFiltering(maxAnisotropy: number): this;
|
|
27
|
+
withMinMipLevel(level: number): this;
|
|
28
|
+
withMaxMipLevel(level: number): this;
|
|
29
|
+
withCompareFunction(compare: GPUCompareFunction): this;
|
|
30
|
+
build(): Sampler;
|
|
31
|
+
}
|
package/dist/Shader.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { WebGPUContext } from "./WebGPUContext";
|
|
3
|
+
import BindGroupLayoutBuilder, { BindGroupBuilder, BindGroupLayout } from "./BindGroup";
|
|
4
|
+
type AttributeMap = Map<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper around GPUShaderModule. Keeps a map of vertex attribute names to
|
|
7
|
+
* shader locations to aid pipeline construction.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Shader {
|
|
10
|
+
/** @internal */
|
|
11
|
+
readonly _inner: GPUShaderModule;
|
|
12
|
+
/** @internal */
|
|
13
|
+
readonly _bindGroupLayouts: BindGroupLayout[] | undefined;
|
|
14
|
+
private _vertexAttributes;
|
|
15
|
+
private _ctx;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
constructor(inner: GPUShaderModule, ctx: WebGPUContext, vertexAttributes: AttributeMap, bindGroupLayouts?: BindGroupLayout[]);
|
|
20
|
+
/**
|
|
21
|
+
* Get the shader location for a named vertex attribute. Returns undefined if the attribute
|
|
22
|
+
* is not declared by the shader.
|
|
23
|
+
*/
|
|
24
|
+
getVertexAttributeLocation(name: string): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if the shader declares a vertex attribute with the given name.
|
|
27
|
+
* @param name
|
|
28
|
+
*/
|
|
29
|
+
hasVertexAttribute(name: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Create a BindGroupBuilder for the shader's bind group at the given index.
|
|
32
|
+
* @param group - index of the bind group declared by the shader
|
|
33
|
+
*/
|
|
34
|
+
createBindGroup(group: number): BindGroupBuilder;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builder for creating shader modules and declaring attribute locations used by the helper
|
|
38
|
+
* pipeline builder.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ShaderBuilder {
|
|
41
|
+
private _code?;
|
|
42
|
+
private _label?;
|
|
43
|
+
private _ctx;
|
|
44
|
+
private _vertexAttributes;
|
|
45
|
+
private _bindGroupLayouts;
|
|
46
|
+
private _includes;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
constructor(ctx: WebGPUContext);
|
|
51
|
+
/** Optional label for the underlying GPUShaderModule. */
|
|
52
|
+
withLabel(label: string): this;
|
|
53
|
+
/** Set WGSL or other shader code to compile into a GPUShaderModule. */
|
|
54
|
+
withCode(code: string): this;
|
|
55
|
+
/**
|
|
56
|
+
* Add a named include to the shader code. The include will be expanded
|
|
57
|
+
* in the shader code before compilation. The include name must be unique
|
|
58
|
+
* within the shader code. This allows using `#include<name>` in the shader
|
|
59
|
+
* code to include other files. While this is not standard WGSL, it's too
|
|
60
|
+
* useful not to support.
|
|
61
|
+
*
|
|
62
|
+
* @param name - The name as used in the `#include<name>` directive.
|
|
63
|
+
* @param code - The code the include should expand to.
|
|
64
|
+
*/
|
|
65
|
+
withInclude(name: string, code: string): this;
|
|
66
|
+
/** Declare a named vertex attribute and the location it maps to in the shader. */
|
|
67
|
+
withVertexAttribute(name: string, location: number): this;
|
|
68
|
+
/**
|
|
69
|
+
* Declare a bind group layout used by this shader. The provided builder
|
|
70
|
+
* callback is used to construct the layout description.
|
|
71
|
+
*/
|
|
72
|
+
withBindGroup(index: number, layout: BindGroupLayout): this;
|
|
73
|
+
withBindGroup(index: number, buildFunc: (builder: BindGroupLayoutBuilder) => void): this;
|
|
74
|
+
/** Compile the shader module and return a `Shader` instance. */
|
|
75
|
+
build(): Shader;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { WebGPUContext } from "./WebGPUContext";
|
|
3
|
+
import { TextureFormat } from "./enums";
|
|
4
|
+
import { IBuffer } from "./buffers/IBuffer";
|
|
5
|
+
import { TextureUsage } from "./buffers/Buffer";
|
|
6
|
+
/**
|
|
7
|
+
* Small wrapper around GPUTexture providing convenience constructors and
|
|
8
|
+
* an internal accessor for low-level interop.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Texture implements IBuffer {
|
|
11
|
+
/** @internal */
|
|
12
|
+
readonly _inner: GPUTexture;
|
|
13
|
+
private _format;
|
|
14
|
+
/**
|
|
15
|
+
* Create a Texture wrapper from an existing GPUTexture.
|
|
16
|
+
* @param texture - The underlying GPUTexture
|
|
17
|
+
*/
|
|
18
|
+
static from_webgpu(texture: GPUTexture, format: TextureFormat): Texture;
|
|
19
|
+
constructor(inner: GPUTexture, format: TextureFormat);
|
|
20
|
+
createView(): TextureViewBuilder;
|
|
21
|
+
get format(): TextureFormat;
|
|
22
|
+
_getBufferResource(): GPUBindingResource;
|
|
23
|
+
}
|
|
24
|
+
export declare class TextureBuilder {
|
|
25
|
+
private _ctx;
|
|
26
|
+
private _size;
|
|
27
|
+
private _data;
|
|
28
|
+
private _format;
|
|
29
|
+
private _usage;
|
|
30
|
+
constructor(ctx: WebGPUContext);
|
|
31
|
+
withSize(width: number, height: number, depthOrArrayLayers?: number): this;
|
|
32
|
+
withData(data: GPUAllowSharedBufferSource): this;
|
|
33
|
+
withFormat(format: TextureFormat): this;
|
|
34
|
+
withImage(data: ImageBitmap): this;
|
|
35
|
+
withUsage(usage: TextureUsage): this;
|
|
36
|
+
build(): Texture;
|
|
37
|
+
}
|
|
38
|
+
export declare class TextureView {
|
|
39
|
+
/** @internal */
|
|
40
|
+
_inner: GPUTextureView;
|
|
41
|
+
constructor(inner: GPUTextureView);
|
|
42
|
+
}
|
|
43
|
+
export declare class TextureViewBuilder {
|
|
44
|
+
private _texture;
|
|
45
|
+
private _desc;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
constructor(texture: Texture);
|
|
50
|
+
withSingleMip(level: number): this;
|
|
51
|
+
withMipRange(start: number, end: number): this;
|
|
52
|
+
withSingleLayer(layer: number): this;
|
|
53
|
+
withLayerRange(start: number, end: number): this;
|
|
54
|
+
build(): TextureView;
|
|
55
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { WebGPUContextOptions } from './WebGPUContext';
|
|
2
|
+
import { CommandEncoder } from "./CommandEncoder";
|
|
3
|
+
import { Texture, TextureBuilder } from "./Texture";
|
|
4
|
+
import { RenderTarget, RenderTargetBuilder } from "./RenderTarget";
|
|
5
|
+
import { ShaderBuilder } from "./Shader";
|
|
6
|
+
import { RenderPipelineBuilder } from "./RenderPipeline";
|
|
7
|
+
import { MeshBuilder } from "./Mesh";
|
|
8
|
+
import { UniformBuffer, UniformBufferLayout, UniformBufferLayoutBuilder } from "./buffers/UniformBuffer";
|
|
9
|
+
import BindGroupLayoutBuilder, { BindGroup, BindGroupBuilder, BindGroupLayout } from "./BindGroup";
|
|
10
|
+
import { SamplerBuilder } from "./Sampler";
|
|
11
|
+
import { ComputePipelineBuilder } from "./ComputePipeline";
|
|
12
|
+
import { ColorSpace, TextureFormat } from "./enums";
|
|
13
|
+
import { BufferBuilder } from "./buffers/Buffer";
|
|
14
|
+
/**
|
|
15
|
+
* Options for initializing TinyHelix
|
|
16
|
+
*/
|
|
17
|
+
export interface TinyHelixOptions extends WebGPUContextOptions {
|
|
18
|
+
/** Optional format to use for the depth/stencil buffer */
|
|
19
|
+
depthStencilFormat?: TextureFormat;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Main entry point for the tiny-helix API. Manages the WebGPU context,
|
|
23
|
+
* backbuffer and provides helpers to create render targets and command encoders.
|
|
24
|
+
*/
|
|
25
|
+
export declare class TinyHelix {
|
|
26
|
+
private _context;
|
|
27
|
+
private _options;
|
|
28
|
+
private _backbuffer?;
|
|
29
|
+
private _backbufferTarget?;
|
|
30
|
+
private _depthStencil?;
|
|
31
|
+
private _depthStencilTarget?;
|
|
32
|
+
private _shaderIncludes;
|
|
33
|
+
private _canvas;
|
|
34
|
+
private _globalBindBufferLayouts;
|
|
35
|
+
private _globalBindBuffers;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new TinyHelix instance. Call `initialize()` before rendering.
|
|
38
|
+
*/
|
|
39
|
+
constructor(canvas: HTMLCanvasElement);
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the underlying WebGPU context and prepares resources.
|
|
42
|
+
* @param options - Configuration options forwarded to the WebGPU context
|
|
43
|
+
* @example await tiny.initialize({ canvas: myCanvas });
|
|
44
|
+
*/
|
|
45
|
+
initialize(options?: TinyHelixOptions): Promise<void>;
|
|
46
|
+
resize(width: number, height: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* Add a named include for all shader code. The include will be expanded
|
|
49
|
+
* in any shader code created through {@link TinyHelix.createShader}.
|
|
50
|
+
* The include name must be unique within the shader code. This allows
|
|
51
|
+
* using `#include<name>` in the shader code to include other files.
|
|
52
|
+
* While this is not standard WGSL, it's too useful not to support.
|
|
53
|
+
'
|
|
54
|
+
* @param name - The name as used in the `#include<name>` directive.
|
|
55
|
+
* @param source - The code the include should expand to.
|
|
56
|
+
*/
|
|
57
|
+
addShaderInclude(name: string, source: string): this;
|
|
58
|
+
/**
|
|
59
|
+
* Return the chosen depth/stencil format if configured.
|
|
60
|
+
*/
|
|
61
|
+
get depthStencilFormat(): TextureFormat | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The current frame's backbuffer texture. Valid after `startFrame()` has been
|
|
64
|
+
* called.
|
|
65
|
+
* @throws Error if accessed before startFrame()
|
|
66
|
+
*/
|
|
67
|
+
get backbuffer(): Texture;
|
|
68
|
+
/**
|
|
69
|
+
* The RenderTarget wrapper for the current backbuffer. Valid after `startFrame()`.
|
|
70
|
+
* @throws Error if accessed before startFrame()
|
|
71
|
+
*/
|
|
72
|
+
get backbufferTarget(): RenderTarget;
|
|
73
|
+
get colorSpace(): ColorSpace;
|
|
74
|
+
get backbufferFormat(): TextureFormat;
|
|
75
|
+
/**
|
|
76
|
+
* The width of the current backbuffer. Valid after `startFrame()`.
|
|
77
|
+
*/
|
|
78
|
+
get backbufferWidth(): number;
|
|
79
|
+
/**
|
|
80
|
+
* The height of the current backbuffer. Valid after `startFrame()`.
|
|
81
|
+
*/
|
|
82
|
+
get backbufferHeight(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Needs to be called before rendering each frame. Updates internal backbuffer
|
|
85
|
+
* references to the current swapchain texture.
|
|
86
|
+
* @example tiny.startFrame();
|
|
87
|
+
*/
|
|
88
|
+
startFrame(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Create a RenderTargetBuilder for a given texture.
|
|
91
|
+
*/
|
|
92
|
+
createRenderTarget(target: Texture): RenderTargetBuilder;
|
|
93
|
+
/**
|
|
94
|
+
* Create a ShaderBuilder for creating a Shader.
|
|
95
|
+
*/
|
|
96
|
+
createShader(): ShaderBuilder;
|
|
97
|
+
/**
|
|
98
|
+
* Create a BindGroupLayoutBuilder for creating a BindGroupLayout.
|
|
99
|
+
*/
|
|
100
|
+
createBindGroupLayout(): BindGroupLayoutBuilder;
|
|
101
|
+
/**
|
|
102
|
+
* Create a BindGroupBuilder for creating a BindGroup.
|
|
103
|
+
*/
|
|
104
|
+
createBindGroup(layout: BindGroupLayout): BindGroupBuilder;
|
|
105
|
+
/**
|
|
106
|
+
* Create a MeshBuilder for creating a Mesh.
|
|
107
|
+
*/
|
|
108
|
+
createMesh(): MeshBuilder;
|
|
109
|
+
/**
|
|
110
|
+
* Create a RenderPipelineBuilder for creating a RenderPipeline.
|
|
111
|
+
*/
|
|
112
|
+
createRenderPipeline(): RenderPipelineBuilder;
|
|
113
|
+
/**
|
|
114
|
+
* Create a ComputePipelineBuilder for creating a ComputePipeline.
|
|
115
|
+
*/
|
|
116
|
+
createComputePipeline(): ComputePipelineBuilder;
|
|
117
|
+
/**
|
|
118
|
+
* Create a SamplerBuilder for creating a Sampler.
|
|
119
|
+
*/
|
|
120
|
+
createSampler(): SamplerBuilder;
|
|
121
|
+
/**
|
|
122
|
+
* Create a TextureBuilder for creating a Texture.
|
|
123
|
+
*/
|
|
124
|
+
createTexture(): TextureBuilder;
|
|
125
|
+
/**
|
|
126
|
+
* Creates a command encoder for recording GPU commands for the current frame.
|
|
127
|
+
* @param label - Optional debug label to assign to the encoder
|
|
128
|
+
*/
|
|
129
|
+
createCommandEncoder(label?: string): CommandEncoder;
|
|
130
|
+
/**
|
|
131
|
+
* Create a UniformBufferLayoutBuilder for creating a UniformBufferLayout.
|
|
132
|
+
*/
|
|
133
|
+
createUniformBufferLayout(): UniformBufferLayoutBuilder;
|
|
134
|
+
/**
|
|
135
|
+
* Create a UniformBuffer for the given layout.
|
|
136
|
+
*/
|
|
137
|
+
createUniformBuffer(layout: UniformBufferLayout): UniformBuffer;
|
|
138
|
+
/**
|
|
139
|
+
* Create a BufferBuilder to construct raw buffers.
|
|
140
|
+
*/
|
|
141
|
+
createBuffer(): BufferBuilder;
|
|
142
|
+
/**
|
|
143
|
+
* Allows setting a global bind group for all render passes. This is useful
|
|
144
|
+
* for setting bind groups that are used by all passes. These buffers will
|
|
145
|
+
* automatically be set for all render and compute passes.
|
|
146
|
+
* @param index - The index of the bind group in the render pipeline layout.
|
|
147
|
+
* @param buffer - The bind group to set.
|
|
148
|
+
*/
|
|
149
|
+
setGlobalBindGroup(index: number, layout: BindGroupLayout, buffer: BindGroup): this;
|
|
150
|
+
/**
|
|
151
|
+
* Destroy the TinyHelix instance and release all GPU resources.
|
|
152
|
+
*/
|
|
153
|
+
destroy(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the current depth/stencil texture if configured.
|
|
156
|
+
*/
|
|
157
|
+
depthStencilTexture(): Texture | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the current depth/stencil RenderTarget if configured.
|
|
160
|
+
*/
|
|
161
|
+
depthStencilTarget(): RenderTarget | undefined;
|
|
162
|
+
private _createDepthStencil;
|
|
163
|
+
}
|