Skip to content

TgpuRoot

[$internal]: object

logOptions: LogGeneratorOptions

packages/typegpu/src/core/root/rootTypes.ts:719


~unstable: Pick<ExperimentalTgpuRoot, "with" | "withCompute" | "createGuardedComputePipeline" | "withVertex" | "pipe" | "beginRenderPass" | "createComparisonSampler" | "createSampler" | "createTexture" | "flush" | "nameRegistrySetting" | "shaderGenerator">

packages/typegpu/src/core/root/rootTypes.ts:905


readonly device: GPUDevice

The GPU device associated with this root.

Unwrapper.device

packages/typegpu/src/core/root/rootTypes.ts:726

get enabledFeatures(): ReadonlySet<GPUFeatureName>

Retrieves a read-only list of all enabled features of the GPU device.

ReadonlySet<GPUFeatureName>

A set of strings representing the enabled features.

packages/typegpu/src/core/root/rootTypes.ts:896

configureContext(options): GPUCanvasContext

Creates and configures context for the provided canvas. Automatically sets the format to navigator.gpu.getPreferredCanvasFormat() if not provided.

ConfigureContextOptions

GPUCanvasContext

An error if no context could be obtained

packages/typegpu/src/core/root/rootTypes.ts:733


createBindGroup<Entries>(layout, entries): TgpuBindGroup<Entries>

Creates a group of resources that can be bound to a shader based on a specified layout.

Entries extends Record<string, null | TgpuLayoutEntry> = Record<string, null | TgpuLayoutEntry>

TgpuBindGroupLayout<Entries>

Layout describing the bind group to be created.

ExtractBindGroupInputFromLayout<Entries>

A record with values being the resources populating the bind group and keys being their associated names, matching the layout keys.

TgpuBindGroup<Entries>

Typed wrapper around a GPUBindGroup.

const fooLayout = tgpu.bindGroupLayout({
foo: { uniform: d.vec3f },
bar: { texture: 'float' },
});
const fooBuffer = ...;
const barTexture = ...;
const fooBindGroup = root.createBindGroup(fooLayout, {
foo: fooBuffer,
bar: barTexture,
});

packages/typegpu/src/core/root/rootTypes.ts:885


createBuffer<TData>(typeSchema, initial?): TgpuBuffer<TData>

Allocates memory on the GPU, allows passing data between host and shader.

TData extends AnyData

ValidateBufferSchema<TData>

The type of data that this buffer will hold.

Infer<NoInfer<TData>>

The initial value of the buffer. (optional)

TgpuBuffer<TData>

Typed wrapper around a GPUBuffer.

packages/typegpu/src/core/root/rootTypes.ts:744

createBuffer<TData>(typeSchema, gpuBuffer): TgpuBuffer<TData>

Allocates memory on the GPU, allows passing data between host and shader.

TData extends AnyData

ValidateBufferSchema<TData>

The type of data that this buffer will hold.

GPUBuffer

A vanilla WebGPU buffer.

TgpuBuffer<TData>

Typed wrapper around a GPUBuffer.

packages/typegpu/src/core/root/rootTypes.ts:759


createComputePipeline<ComputeIn>(descriptor): TgpuComputePipeline

ComputeIn extends IORecord<AnyComputeBuiltin>

Descriptor<ComputeIn>

TgpuComputePipeline

WithBinding.createComputePipeline

packages/typegpu/src/core/root/rootTypes.ts:253


createGuardedComputePipeline<TArgs>(callback): TgpuGuardedComputePipeline<TArgs>

Creates a compute pipeline that executes the given callback in an exact number of threads. This is different from withCompute(...).createPipeline() in that it does a bounds check on the thread id, where as regular pipelines do not and work in units of workgroups.

TArgs extends number[]

(…args) => void

A function converted to WGSL and executed on the GPU. It can accept up to 3 parameters (x, y, z) which correspond to the global invocation ID of the executing thread.

TgpuGuardedComputePipeline<TArgs>

If no parameters are provided, the callback will be executed once, in a single thread.

const fooPipeline = root
.createGuardedComputePipeline(() => {
'use gpu';
console.log('Hello, GPU!');
});
fooPipeline.dispatchThreads();
// [GPU] Hello, GPU!

One parameter means n-threads will be executed in parallel.

const fooPipeline = root
.createGuardedComputePipeline((x) => {
'use gpu';
if (x % 16 === 0) {
// Logging every 16th thread
console.log('I am the', x, 'thread');
}
});
// executing 512 threads
fooPipeline.dispatchThreads(512);
// [GPU] I am the 256 thread
// [GPU] I am the 272 thread
// ... (30 hidden logs)
// [GPU] I am the 16 thread
// [GPU] I am the 240 thread

WithBinding.createGuardedComputePipeline

packages/typegpu/src/core/root/rootTypes.ts:417


createMutable<TData>(typeSchema, initial?): TgpuMutable<TData>

Allocates memory on the GPU, allows passing data between host and shader. Can be mutated in-place on the GPU. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateStorageSchema<TData>

The type of data that this buffer will hold.

Infer<NoInfer<TData>>

The initial value of the buffer. (optional)

TgpuMutable<TData>

packages/typegpu/src/core/root/rootTypes.ts:799

createMutable<TData>(typeSchema, gpuBuffer): TgpuMutable<TData>

Allocates memory on the GPU, allows passing data between host and shader. Can be mutated in-place on the GPU. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateStorageSchema<TData>

The type of data that this buffer will hold.

GPUBuffer

A vanilla WebGPU buffer.

TgpuMutable<TData>

packages/typegpu/src/core/root/rootTypes.ts:813


createQuerySet<T>(type, count, rawQuerySet?): TgpuQuerySet<T>

Creates a query set for collecting timestamps or occlusion queries.

T extends GPUQueryType

T

The type of queries to collect (‘occlusion’ or ‘timestamp’).

number

The number of queries in the set.

GPUQuerySet

An optional pre-existing GPUQuerySet to use instead of creating a new one.

TgpuQuerySet<T>

Typed wrapper around a GPUQuerySet.

packages/typegpu/src/core/root/rootTypes.ts:855


createReadonly<TData>(typeSchema, initial?): TgpuReadonly<TData>

Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for large data. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateStorageSchema<TData>

The type of data that this buffer will hold.

Infer<NoInfer<TData>>

The initial value of the buffer. (optional)

TgpuReadonly<TData>

packages/typegpu/src/core/root/rootTypes.ts:826

createReadonly<TData>(typeSchema, gpuBuffer): TgpuReadonly<TData>

Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for large data. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateStorageSchema<TData>

The type of data that this buffer will hold.

GPUBuffer

A vanilla WebGPU buffer.

TgpuReadonly<TData>

packages/typegpu/src/core/root/rootTypes.ts:840


createRenderPipeline<TVertexIn, TAttribs, TVertexOut, TFragmentOut>(descriptor): TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>

TVertexIn extends In = Record<string, any>

TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>

TVertexOut = unknown

TFragmentOut = unknown

DescriptorBase & object

TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>

WithBinding.createRenderPipeline

packages/typegpu/src/core/root/rootTypes.ts:257

createRenderPipeline<TVertexIn, TAttribs, TVertexOut>(descriptor): TgpuRenderPipeline<Void>

TVertexIn extends In = Record<string, any>

TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>

TVertexOut extends Out = Out

DescriptorBase & object

TgpuRenderPipeline<Void>

WithBinding.createRenderPipeline

packages/typegpu/src/core/root/rootTypes.ts:286

createRenderPipeline<TVertexIn, TAttribs, TVertexOut, TFragmentOut>(descriptor): TgpuRenderPipeline<Void> | TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>

TVertexIn extends In = Record<string, any>

TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>

TVertexOut extends Out = Out

TFragmentOut = unknown

DescriptorBase & {attribs: TAttribs;fragment: TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Assume<TFragmentOut, Out>> | (input) => AutoFragmentOut<Assume<TFragmentOut, v4f | AnyAutoCustoms>>;targets: FragmentOutToTargets<NoInfer<TFragmentOut>>;vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, Out>> | (input) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>; } | {attribs: TAttribs;fragment: TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Record<string, never>> | (input) => undefined;targets: undefined;vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, Out>> | (input) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>; }

TgpuRenderPipeline<Void> | TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>

WithBinding.createRenderPipeline

packages/typegpu/src/core/root/rootTypes.ts:315


createUniform<TData>(typeSchema, initial?): TgpuUniform<TData>

Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for small data. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateUniformSchema<TData>

The type of data that this buffer will hold.

Infer<NoInfer<TData>>

The initial value of the buffer. (optional)

TgpuUniform<TData>

packages/typegpu/src/core/root/rootTypes.ts:772

createUniform<TData>(typeSchema, gpuBuffer): TgpuUniform<TData>

Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for small data. For a general-purpose buffer, use TgpuRoot.createBuffer.

TData extends AnyWgslData

ValidateUniformSchema<TData>

The type of data that this buffer will hold.

GPUBuffer

A vanilla WebGPU buffer.

TgpuUniform<TData>

packages/typegpu/src/core/root/rootTypes.ts:786


destroy(): void

Destroys all underlying resources (i.e. buffers…) created through this root object. If the object is created via tgpu.init instead of tgpu.initFromDevice, then the inner GPU device is destroyed as well.

void

packages/typegpu/src/core/root/rootTypes.ts:903


pipe(transform): WithBinding

(cfg) => Configurable

WithBinding

WithBinding.pipe

packages/typegpu/src/core/root/rootTypes.ts:429


unwrap(resource): GPUComputePipeline

TgpuComputePipeline

GPUComputePipeline

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:13

unwrap(resource): GPURenderPipeline

TgpuRenderPipeline

GPURenderPipeline

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:14

unwrap(resource): GPUBindGroupLayout

TgpuBindGroupLayout

GPUBindGroupLayout

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:15

unwrap(resource): GPUBindGroup

TgpuBindGroup

GPUBindGroup

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:16

unwrap(resource): GPUBuffer

TgpuBuffer<BaseData>

GPUBuffer

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:17

unwrap(resource): GPUTextureView

TgpuTextureView

GPUTextureView

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:18

unwrap(resource): GPUVertexBufferLayout

TgpuVertexLayout

GPUVertexBufferLayout

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:19

unwrap(resource): GPUSampler

TgpuSampler

GPUSampler

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:20

unwrap(resource): GPUSampler

TgpuComparisonSampler

GPUSampler

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:21

unwrap(resource): GPUQuerySet

TgpuQuerySet<GPUQueryType>

GPUQuerySet

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:22

unwrap(resource): GPUTexture

TgpuTexture

GPUTexture

Unwrapper.unwrap

packages/typegpu/src/unwrapper.ts:23


with<T>(slot, value): WithBinding

T

TgpuSlot<T>

Eventual<T>

WithBinding

WithBinding.with

packages/typegpu/src/core/root/rootTypes.ts:197

with<T>(accessor, value): WithBinding

T extends BaseData

TgpuAccessor<T>

In<NoInfer<T>>

WithBinding

WithBinding.with

packages/typegpu/src/core/root/rootTypes.ts:198

with<T>(accessor, value): WithBinding

T extends BaseData

TgpuMutableAccessor<T>

In<NoInfer<T>>

WithBinding

WithBinding.with

packages/typegpu/src/core/root/rootTypes.ts:199


withCompute<ComputeIn>(entryFn): WithCompute

ComputeIn extends IORecord<AnyComputeBuiltin>

TgpuComputeFn<ComputeIn>

WithCompute

WithBinding.withCompute

packages/typegpu/src/core/root/rootTypes.ts:249


withVertex<VertexIn, VertexOut>(entryFn, …args): WithVertex<VertexOut>

VertexIn extends In

VertexOut extends Out

TgpuVertexFn<VertexIn, VertexOut>

OptionalArgs<LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>>

WithVertex<VertexOut>

WithBinding.withVertex

packages/typegpu/src/core/root/rootTypes.ts:424